Macro to delete rows based on a certain value in a cell

excelnewbie1986

New Member
Joined
May 16, 2018
Messages
16
Hi everyone,

I have an Excel spreadsheet with a column (column Z) that contains multiple values (C, G, M and S). I would like to create a Macro to delete the rows that contain the value of G in this particular column. So, for example, if cell Z18 has a value of G I'd like the Macro to delete the entire row 18 and move the next row of data up by one row to replace the blank row that's been left by the deletion. I know I can sort the spreadsheet and manually delete rows that contain G, but there are 84,000 rows of data, and over 500 instances of G that I want removing. I've never created a Macro before and would really appreciate your help in guiding me to create the Macro.

Thank you so much!!!
AP
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Hi & welcome to MrExcel.
How about
Code:
Sub delG()
Application.ScreenUpdating = False
   With Range("Z:Z")
      .Replace "G", "=GGG", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
   End With
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
Code:
Sub delG()
Application.ScreenUpdating = False
   With Range("Z:Z")
      .Replace "G", "=GGG", xlWhole, , False, , False, False
      .SpecialCells(xlFormulas, xlErrors).EntireRow.Delete
   End With
End Sub

Thank you so much! Works perfectly! :)
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,378
Messages
6,119,188
Members
448,873
Latest member
jacksonashleigh99

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