vba variable value via cell reference

  • Thread starter Bill (Unique as my name)
  • Start date
B

Bill (Unique as my name)

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.
 
D

Dana DeLouis

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
 
Top