Assistance: For Next Loop?

Joined
Jan 2, 2014
Messages
5
Reaction score
0
Good evening

I wonder if anyone can tell me if there is a shorter way of writing the below code - perhaps a 'For Next Loop?

There are 40 Lines to be wrtten, with the target cell and the formula referenced cell increasing by one each time.

With ActiveSheet
.Range("A181").Formula = "=IF($AA$2<2,"""",A180+2)"
.Range("A182").Formula = "=IF($AA$2<2,"""",A181+2)"
.Range("A183").Formula = "=IF($AA$2<2,"""",A182+2)"
.Range("A184").Formula = "=IF($AA$2<2,"""",A183+2)"
.Range("A185").Formula = "=IF($AA$2<2,"""",A184+2)"
etc....
End With

Any help much appreciated.
 
Hi,

Here is what I tried....

Sub Test1

st_row = 181
end_row = st_row + 40

Do While st_row <= end_row
GoSub Write_Formula
st_row = st_row + 1
Loop

Exit Sub



Write_Formula:
With ActiveSheet
.Range("A" & st_row).Formula = "=IF($AA$2<2,"""",A" & st_row - 1 & "+2)"
End With
Return

End Sub
 
Back
Top