I have a worksheet named "subtotal" where I am identifying 2 line to be subtracted with 1 & 2 (line with "2" should be subtracted from line with "1"). I need to insert a row below the line with "2" in order to add the correct formula in the required cells. I am selecting the column containing the criteria (1,2), then executing a find comand for the "2", I then use the offset property to select the cell below and insert a row. This works great, however when I apply the loop it will not stop. I have indicated that if the active cell = "2XXXXX" then exit Do. I have tried several variations and end up with the same endless loop. Can anyone tell me what i am doing wrong? Here is my code:
Sub insert_row_1()
'
Range("D1").Select
Selection.End(xlDown).Activate
ActiveCell.Offset(1, 0).Activate
ActiveCell.FormulaR1C1 = "2XXXXX"
Range("A1").Select
Columns("D:D").Select
Selection.Find(What:="2", After:=ActiveCell, LookIn:=xlValues, LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Do
If ActiveCell.Value = "2" Then
ActiveCell.Offset(1, 0).Activate
ActiveCell.EntireRow(1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
ElseIf ActiveCell.Value <> "2" Then
With Columns("D")
Selection.FindNext(After:=ActiveCell).Activate
ActiveCell.Offset(1, 0).Activate
ActiveCell.EntireRow(1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
End With
ElseIf ActiveCell.Value = "2XXXXX" Then
Exit Do
End If
Loop
End Sub