ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referencing variable in a loop (https://www.excelbanter.com/excel-programming/356046-referencing-variable-loop.html)

JeffMelton

Referencing variable in a loop
 
I don't know why I can't figure this out. I have a lot of variables
already defined A1, A2, A3 etc etc.

I'm running a loop and would like to call the needed variable like this

For i= 1 to 100
LR = Lastrow + i
Range("A"& LR) = A & i - G & i
next

is this not possible or something?


Jim Cone

Referencing variable in a loop
 
Sub TheBeesKnees()
Dim i As Long
Dim LR As Long
Dim G As Long
Dim A As Long
Dim LastRow As Long
A = 5
G = 10
LastRow = 15

For i = 1 To 100
LR = LastRow + i
Cells(LR, 1).Value = A + i - G + i
Next 'i
End Sub

Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"JeffMelton" wrote in message...
I don't know why I can't figure this out. I have a lot of variables
already defined A1, A2, A3 etc etc.

I'm running a loop and would like to call the needed variable like this

For i= 1 to 100
LR = Lastrow + i
Range("A"& LR) = A & i - G & i
next

is this not possible or something?



All times are GMT +1. The time now is 12:03 AM.

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