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
 

Some videos you may like

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

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,036
Office Version
  1. 365
Platform
  1. Windows
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
 

excelnewbie1986

New Member
Joined
May 16, 2018
Messages
16
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! :)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,036
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,778
Messages
5,598,027
Members
414,204
Latest member
Excelmee

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