Delete all row except those tat start with specific text

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,147
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everone,
I'd like a macro that could delete every row in the active worksheet except the ones that start with the text "Start Date" , "End Date" "Time" and "Money out"

so i end up with just a small list of these rows?
any idea how i can do this?

Tony
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

tlowry

Well-known Member
Joined
Nov 3, 2011
Messages
1,367
This does what I think you asked for:

Code:
Sub DeleteRows()
    Dim istr, lr
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For istr = 1 To lr
        Cells(istr, 1) = SaveOrNot(Cells(istr, 1).Text)
    Next
    On Local Error Resume Next
    Range("A1:A" & lr).Cells. _
        SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
End Sub
Function SaveOrNot(sCheck)
    SaveOrNot = sCheck
    If InStr(sCheck, "Start Date") = 1 Then Exit Function
    If InStr(sCheck, "End Date") = 1 Then Exit Function
    If InStr(sCheck, "Time") = 1 Then Exit Function
    If InStr(sCheck, "Money out") = 1 Then Exit Function
    SaveOrNot = "#N/A"
End Function
 
Upvote 0

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,147
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Thank you tlowry, this looks great, i'll give it a test now.
Thank you very much for your help.

Tony
 
Upvote 0

Forum statistics

Threads
1,195,671
Messages
6,011,075
Members
441,581
Latest member
rp4717

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top