VBA How to delete rows in column G that begin with...

Tardisgx

Board Regular
Joined
May 10, 2018
Messages
81
I've tried recording,editing multiple recordings, understanding other forum posts, the kutools vba is useless.

The sheet is called "Columns"; column G has a header and the number of rows occupied will vary.

There are 19 If the cell begins with "x" delete the rows These keywords will stay the same.

I need this in the middle of a bigger macro- something i've made for my work; its not "elegant" and too long to paste here-

Loops are beyond my understanding and ive not been able to just paste one in the middle of a macro successfully.

Any help is appreciated.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
What exactly do you mean by
There are 19 If the cell begins with "x" delete the rows These keywords will stay the same.
 
Upvote 0
1 If cell in column G begins with tiger delete these rows
2 If cell in column G begins with bear delete these rows
...
19 If cell in column G begins with rat delete these rows

Columns A-I are occupied if that's relevant. I recorded data filter ect but I couldnt get it to do all 19 successfully.
 
Last edited:
Upvote 0
On another sheet (I've called it List) in A1 put the header of the column you want to filter.
Underneath that put the 19 values & run this
Code:
Sub Macro4()
   With Sheets("[COLOR=#ff0000]Sheet1[/COLOR]")
      .Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
         Sheets("[COLOR=#ff0000]List[/COLOR]").Range("A1:A20"), Unique:=False
      .Range("A1").CurrentRegion.Offset(1).EntireRow.Delete
      .ShowAllData
   End With
End Sub
Change sheet names to suit
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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