Delete Every Zero Value in Same Column In Every Worksheet

stuartgb100

Active Member
Joined
May 10, 2015
Messages
322
Office Version
  1. 2021
Platform
  1. Windows
Hi,

In column "G", Rows 7 - 2,000 there are mainly numbers, but some text.
Many cells show as 0 (ie zero), and I would like to delete these.
I have over a hundred sheets to deal with.
The workbook I have been given is over 6 Mb.

How do I loop through each worksheet and also loop through each cell in the range "G7:G200" please ?
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Are you trying to delete the whole row, or just clear the 0 entry out of that cell?

If the later, you can use Find/Replace on column G of all sheets and replace the 0's with nothing.
If you turn on the Macro Recorder while you perform this step manually on one sheet, it will give you the VBA code you need to do that.
If you need to see what VBA code that loops through all sheets of a workbook looks like, have a look at this post I just made here: https://www.mrexcel.com/forum/excel...d-specific-text-end-all-tabs.html#post4937304
 
Upvote 0
Are there any sheets that shouldn't be done?
If so, whee I've got the If sht.Name <> "Control" etc put your sheet names you don't want done in there. If you've no sheets remove the IF statement and End If at the bottom

Add a module to your workbook or personal.xlsb
Add this

Then run it
Turning Calculation mode to manual speeds it up.
Also, unmaximise your screen size and make the Excel window quite small, deleting rows forces Excel to refresh toe view and the smaller it is the faster it is.

You use Step -1 and start at the bottom because if you start at the top, when you delete a row, the rows below shift up and you would need to deal with the row that had shifted up before carrying on down. Starting at the bottom avoids this problem

Code:
Sub DelZeros
Application.Calculation = xlCalculationManual
For each sht in ActiveWorkbook.Sheets
   if sht.Name <> "Control" And sht.Name <> "Summary" Then
       For RowCounter = 2000 to 7 Step -1
           If sht.Cells(RowCounter,7).Value = 0 Then sht.Range("A"&RowCounter).EntireRow.Delete
       Next RowCounter
    End If
Next sht
Application.Calculation = xlCalculationAutomatic
End Sub
 
Last edited:
Upvote 0
Upvote 0
Many thanks to all for their reply.

Plenty here for me to work with.

Sorry I wasn't clear - just trying to delete the value (clear the cell) if it's a zero.

Thanks again.
 
Upvote 0
Try this:
Code:
Sub MyMacro()

    Dim ws As Worksheet

    Application.ScreenUpdating = False

    For Each ws In Worksheets
        ws.Range("G7:G2000").Replace What:="0", Replacement:="", LookAt:=xlWhole, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
    Next ws
    
    Application.ScreenUpdating = True
    
End Sub
 
Last edited:
Upvote 0
Just reread your post, if you don't want to delete the entire row use this

Code:
Sub DelZeros
Application.Calculation = xlCalculationManual
For each sht in ActiveWorkbook.Sheets
   if sht.Name <> "Control" And sht.Name <> "Summary" Then
       For RowCounter = 2000 to 7 Step -1
           If sht.Cells(RowCounter,7).Value = 0 Then sht.Range("G"&RowCounter).Delete Shift:=xlUp
       Next RowCounter
    End If
Next sht
Application.Calculation = xlCalculationAutomatic
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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