I'm not sure if it was worth the effort to use Find/FindNext because of all
the problems I ran into. I show you tow methods and you decide which is
better
Sub DeleteRows()
With ActiveSheet
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
Set DataRange = .Range("A1", .Cells(LastRow, LastCol))
For ColCount = 1 To LastCol
Header = .Cells(1, ColCount)
Set HeaderCell = .Cells(1, ColCount)
Set c = DataRange.Find(what:=Header, LookIn:=xlValues,
SearchOrder:=xlByRows, _
after:=Cells(1, LastCol))
If Not c Is Nothing And c.Row <> 1 Then
Do
Set EndRow = Cells(c.Row - 1, LastCol)
c.EntireRow.Delete
Set c = DataRange.Find(what:=Header, after:=EndRow, _
LookIn:=xlValues, SearchOrder:=xlByRows)
Loop While Not c Is Nothing And c.Row <> 1
End If
Next ColCount
End With
End Sub
or
Sub DeleteRows2()
With ActiveSheet
LastCol = .Cells(1, Columns.Count).End(xlToLeft).Column
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
Set Headers = .Range("A1", .Cells(1, LastCol))
RowCount = LastRow
Do While RowCount >= 2
For Each Header In Headers
Set RowCells = .Range(.Cells(RowCount, "A"), .Cells(RowCount,
LastCol))
Set c = RowCells.Find(what:=Header, LookIn:=xlValues)
If Not c Is Nothing Then
Rows(RowCount).Delete
Exit For
End If
Next Header
RowCount = RowCount - 1
Loop
End With
End Sub