Delete all row except those tat start with specific text

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
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

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
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
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,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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
Back
Top