M
mike_vr
Hi there, wonder if anyone can help. Relatively new to loops, and can't get
it to stop looping!!
Here's the code, trying to insert a row after every cell that has "Total for
department" (number of occurences vary each time), and whilst the row gets
added, it then loops back to the beginning and adds multiple rows.
Any thoughts?
Thanks, Mike
Sub Abbey3()
Dim i As Integer
Dim thisrow As Integer
For i = 1 To Selection.CurrentRegion.Rows.Count - 1
Cells.Find(What:="Total for Department", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
thisrow = Selection.Row
Rows(thisrow + 1).EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Next i
End Sub
it to stop looping!!
Here's the code, trying to insert a row after every cell that has "Total for
department" (number of occurences vary each time), and whilst the row gets
added, it then loops back to the beginning and adds multiple rows.
Any thoughts?
Thanks, Mike
Sub Abbey3()
Dim i As Integer
Dim thisrow As Integer
For i = 1 To Selection.CurrentRegion.Rows.Count - 1
Cells.Find(What:="Total for Department", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
thisrow = Selection.Row
Rows(thisrow + 1).EntireRow.Insert
ActiveCell.Offset(1, 0).Select
Next i
End Sub