Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 156
Default VBA basic question

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default VBA basic question

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

--
Cheers
Nigel



"kirkm" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default VBA basic question

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


"kirkm" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default VBA basic question

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

"kirkm" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default VBA basic question

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

--
HTH :)
Dana DeLouis
Windows XP & Office 2003


"kirkm" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default VBA basic question

Please don't multipost.

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


"kirkm" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Very basic VBA question. Cerberus Excel Discussion (Misc queries) 1 July 21st 08 04:30 PM
basic question M121385 New Users to Excel 4 May 6th 08 06:22 PM
Basic VBA Question amirstal Excel Programming 2 December 20th 06 02:39 PM
Basic question plittle Excel Discussion (Misc queries) 1 May 23rd 06 03:49 PM
Basic VBA question Henrik[_2_] Excel Programming 2 October 25th 03 12:23 AM


All times are GMT +1. The time now is 07:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"