T
Tesla5000
Hi,
I am new to VBA and just finished my first program which is working well but
I have a question about part of it. At one point in the process I have the
macro search out a cell with a certain value and then I want it to insert 21
rows after that cell. For some reason in order to get 21 rows I have to run
the loop 42 times. Below is how I did it. It inserts 21 rows. Does anyone
know why I have to loop twice as many times as I think I should. Also I am
sure there is a more efficient way to do this and would welcome learning a
quicker way to acheive the same goal.
Thanks for your help.
' Insert 21 rows after NOI
i = 0
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = "Net Operating Income" Then
Cell.Select
For i = 1 To 42
Rows(ActiveCell(2).Row).Insert
i = i + 1
Next i
End If
Next Cell
I am new to VBA and just finished my first program which is working well but
I have a question about part of it. At one point in the process I have the
macro search out a cell with a certain value and then I want it to insert 21
rows after that cell. For some reason in order to get 21 rows I have to run
the loop 42 times. Below is how I did it. It inserts 21 rows. Does anyone
know why I have to loop twice as many times as I think I should. Also I am
sure there is a more efficient way to do this and would welcome learning a
quicker way to acheive the same goal.
Thanks for your help.
' Insert 21 rows after NOI
i = 0
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = "Net Operating Income" Then
Cell.Select
For i = 1 To 42
Rows(ActiveCell(2).Row).Insert
i = i + 1
Next i
End If
Next Cell