PDA

View Full Version : Loop question



baron11
11-24-2008, 12:57 PM
I have a simple VBA code

For period = 0 to 100 Step 10

Sheets("sheet1").Select
Range("A1").Select
ActiveCell.Formula= period
Sheets("sheet2").Select
Range ("B1").Select
ActiveCell.Formula="=Sheet1R5C5"

Next period

End period.

Basically, I change a variable in sheet1 cell A1 and that creates a new value for the formula output in cell E5. I paste this output in cell B1 on sheet2.

My question is, how do I work with the loop so that the next value of period in the loop gets posted in cell B2 and not B1 again.

Thanks a lot for your answer.

Tommy
11-24-2008, 04:09 PM
I think there is an error atActiveCell.Formula="=Sheet1R5C5"


Dim RowCnt As Long
RowCnt = 1
For Period = 0 To 100 Step 10
Worksheets("sheet1").Cells(1, 1).Formula = Period
'Sheets("sheet1").Select
'Range("A1").Select
'ActiveCell.Formula = Period
'row, column
Worksheets("sheet2").Cells(RowCnt, 2).Formula = "=Sheet1R5C5"
RowCnt = RowCnt + 1
'Sheets("sheet2").Select
'Range("B1").Select
'ActiveCell.Formula = "=Sheet1R5C5"
Next Period