ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA question (https://www.excelbanter.com/excel-programming/380292-vba-question.html)

kirkm[_6_]

VBA 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

Gary Keramidas

VBA question
 
maybe try something like this, i wouldn't use p$ as a variable.

Sub test()
Dim c As Range
Dim pstr As String
pstr = "C3:C20"
With Worksheets("Stats")
For Each c In .Range(pstr)
Debug.Print c.Value
Next
End With
End Sub

--


Gary


"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




JMB

VBA question
 
With regards to your original code, I think you want .Cells instead of .Range

With Worksheets("Stats").Range(p$)

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

End With


"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



All times are GMT +1. The time now is 10:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com