Macro to Delete rows in Col A contining certain text

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I need code to delete rows containing the folowing text in "Total" Col A on sheet "Statement" for e.g

Total Parts Transactions
Total Other Receivables Transactions

Your assistance in this regar is most appreciated
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hi, try this...
VBA Code:
Sub test()

    Dim rng As Range
    With Sheets("Statement")
        Set rng = .Range("A1:A" & .Cells(Rows.Count, 1).End(3).Row)
    End With

    Dim cell As Range, dRow As Range
    Set dRow = Range("IV1")
    For Each cell In rng.Cells
        If InStr(cell.Value, "Total") Then
            Set dRow = Union(dRow, cell)
        End If
    Next cell
    If dRow.Cells.Count > 1 Then Intersect(dRow, Columns(1)).EntireRow.Delete

End Sub
 
Upvote 0
Assuming headers are in row 1, try:
VBA Code:
Sub DeleteRows()
    With Sheets("Statement")
        .Range("A1").CurrentRegion.AutoFilter 1, "=*Total*"
        .AutoFilter.Range.Offset(1).EntireRow.Delete
        .Range("A1").AutoFilter
    End With
End Sub
 
Upvote 0
Many thanks for the help guys. Both your code works perfectly
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,873
Members
449,056
Latest member
ruhulaminappu

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