create a loop macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

how can i create a macro that look for a data in a cell, delete the row in
that cell, delete 7 rows down, and repeat the action until it find no more
cells containing the data. Thanks so much for your help.
 
Sub DeleteData()
Dim rng As Range
Dim target As String
target = InputBox("Enter Search Term")
If target = "" Then Exit Sub
Do
If Not rng Is Nothing Then
rng.Resize(8, 1).EntireRow.Delete
End If
Set rng = Nothing
Set rng = Cells.Find(What:=target, _
After:=ActiveCell, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
Loop While Not rng Is Nothing
End Sub


obviously test this on a copy of your workbook/data.
 

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

Back
Top