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.
 
Joined
Feb 21, 2018
Messages
216
Reaction score
86
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top