I want to delete specified number of rows after a found value in a column. I find a search value in A3 then I want to delete rows from 4th row to specified number of rows say from 4 th row to 11th row. My code deletes alternate rows. If I specify ~Rows("cnt1:cnt2") it gives error. Need guidance to correct the error in my code. Images before and after code run are given below. It should delete consecutive rows containing aa,bb,cc,dd.....
Code followed by me is given below.
Sub Asearch()
Dim found As Range
Dim FR As Long
Dim cnt1 As Long
Dim cnt2 As Long
Set found = Sheets("Sheet1").Columns("A").Find(what:="Swati", LookIn:=xlValues, lookat:=xlWhole)
If found Is Nothing Then
MsgBox "Not found"
Else
MsgBox "Found on row " & found.Row
FR = found.Row
cnt1 = FR + 1
Debug.Print cnt1
cnt2 = 11
Do While cnt1 <= cnt2
Rows(cnt1).EntireRow.Delete
cnt1 = cnt1 + 1
Debug.Print cnt1
Loop
End If
End Sub
EDIT of the post based on @micstr guidance. Problem is solved. Updated code is given below.
Sub Asearch2()
Dim found As Range
Dim FR As Long
Dim cnt1 As Long
Dim cnt2 As Long
Set found = Sheets("Sheet1").Columns("A").Find(what:="Swati", LookIn:=xlValues, lookat:=xlWhole)
If found Is Nothing Then
MsgBox "Not found"
Else
MsgBox "Found on row " & found.Row
FR = found.Row
cnt1 = FR + 1
Debug.Print cnt1
cnt2 = 11
Do While cnt2 >= cnt1
Rows(cnt2).EntireRow.Delete
cnt2 = cnt2 - 1
Debug.Print cnt2
Loop
End If
End Sub

