Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2006

Tip: Looking for answers? Try searching our database.

VBA basic question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kirkm - 31 Dec 2006 06:29 GMT
I should know why this doesn't work...but
get 'Wrong number of arguments or invalid property assignment'
and can't resolve it.

With Worksheets("Stats").Range(p$)
 
   For Each c In .Range
       Debug.Print c.Value
   Next

End With

The value of p$ is "C3:C20"

Many thanks - Kirk
Nigel - 31 Dec 2006 07:58 GMT
You cannot name a range p$ try this.....

Dim p As Range, c As Range
Set p = Range("C3:C20")

With Worksheets("Stats")

   For Each c In p
       Debug.Print c.Value
   Next

End With

Signature

Cheers
Nigel

>I should know why this doesn't work...but
> get 'Wrong number of arguments or invalid property assignment'
[quoted text clipped - 11 lines]
>
> Many thanks - Kirk
SongBear - 31 Dec 2006 08:21 GMT
kirkm, You are doing the range thing twice; this will work:

Sub MacroTaDa()
Dim p$
p$ = "C3:C20"

With Worksheets("Stats")
   For Each c In .Range(p$)
       Debug.Print c.Value
   Next
End With

End Sub

> I should know why this doesn't work...but
> get 'Wrong number of arguments or invalid property assignment'
[quoted text clipped - 11 lines]
>
> Many thanks - Kirk
SongBear - 31 Dec 2006 08:28 GMT
Or this will work:
Sub MacroTaDa2()
Dim p$
p$ = "C3:C20"

   For Each c In Worksheets("Stats").Range(p$)
       Debug.Print c.Value
   Next

End Sub

> I should know why this doesn't work...but
> get 'Wrong number of arguments or invalid property assignment'
[quoted text clipped - 11 lines]
>
> Many thanks - Kirk
Dana DeLouis - 31 Dec 2006 13:42 GMT
> With Worksheets("Stats").Range(p$)
>    For Each c In .Range

Hi.  You have answers from others.
Just to point out, your method would work if you drilled one level down  ie.
"Cells" instead of "Range."

Sub Demo()
 Dim P$
 Dim C As Range
 P$ = "C3:C20"

 With Worksheets("Stats").Range(P$)
   For Each C In .Cells
     Debug.Print C.Value
   Next
 End With
End Sub

Signature

HTH   :>)
Dana DeLouis
Windows XP & Office 2003

>I should know why this doesn't work...but
> get 'Wrong number of arguments or invalid property assignment'
[quoted text clipped - 11 lines]
>
> Many thanks - Kirk
JMB - 31 Dec 2006 17:39 GMT
Please don't multipost.

http://www.cpearson.com/excel/newposte.htm

> I should know why this doesn't work...but
> get 'Wrong number of arguments or invalid property assignment'
[quoted text clipped - 11 lines]
>
> Many thanks - Kirk
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.