Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel - Delete rows but keep the header

Status
Not open for further replies.

tourcd

IS-IT--Management
Dec 5, 2005
37
Hi,

I've got the following macro which runs through my spreadsheet looking for the word 'Heading' in column A. It deletes any row which contains the word 'Heading', great. However I would like it to keep the first occurance of 'Heading' and then continue to delete the rest. I'd then like it to loop through and do the same for 'Heading2' etc.

Can anyone point me in the right direction?

Public Sub FormatInput()
'
' FormatInput Macro
'
' Turn off screen updating to speed up macro.
Application.ScreenUpdating = False

Dim T As Range
Dim SrchRng

Set SrchRng = ActiveSheet.Range("A1", ActiveSheet.Range("A65536").End(xlUp))
Do
Set T = SrchRng.Find("Heading", LookIn:=xlValues)
If Not T Is Nothing Then T.EntireRow.Delete
Loop While Not T Is Nothing
'
' Turn screen updating back on.
Application.ScreenUpdating = True
End Sub
 



Hi,

Please post VBA (Macro) questions in Forum707.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top