ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   vba variable value via cell reference (https://www.excelbanter.com/excel-discussion-misc-queries/120425-vba-variable-value-via-cell-reference.html)

Bill (Unique as my name)

vba variable value via cell reference
 
I do not know the proper syntax
for the fourth line of this sample code.

1. Dim S as Long
2. Dim X as Long
3. For X = 5 To 55
4. S = Range("G&'X'&")
5. Next x

Please change my gloomy day to a bright shining wonder.


Bob Phillips

vba variable value via cell reference
 
S = Range("G" & X)


"Bill (Unique as my name)" wrote in message
oups.com...
I do not know the proper syntax
for the fourth line of this sample code.

1. Dim S as Long
2. Dim X as Long
3. For X = 5 To 55
4. S = Range("G&'X'&")
5. Next x

Please change my gloomy day to a bright shining wonder.




Bill (Unique as my name)

vba variable value via cell reference
 
Thanks Bob!

Bob Phillips wrote:
S = Range("G" & X)


"Bill (Unique as my name)" wrote in message
oups.com...
I do not know the proper syntax
for the fourth line of this sample code.

1. Dim S as Long
2. Dim X as Long
3. For X = 5 To 55
4. S = Range("G&'X'&")
5. Next x

Please change my gloomy day to a bright shining wonder.



Dana DeLouis

vba variable value via cell reference
 
for the fourth line of this sample code.
4. S = Range("G&'X'&")


If I understand correctly, perhaps one of these ideas:

Sub Demo()
Dim S As Long
Dim X As Long
For X = 5 To 55
S = Range("G" & X)
Next X
End Sub

'Or perhaps to avoid using strings...

Sub Demo2()
Dim S As Long
Dim R As Long '(R)ow
For R = 5 To 55
S = Cells(R, 7)
Next R
End Sub

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


"Bill (Unique as my name)" wrote in message
oups.com...
I do not know the proper syntax
for the fourth line of this sample code.

1. Dim S as Long
2. Dim X as Long
3. For X = 5 To 55
4. S = Range("G&'X'&")
5. Next x

Please change my gloomy day to a bright shining wonder.





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

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