VBA Delete zeros if blank cell found in D

Miya

Well-known Member
Joined
Nov 29, 2008
Messages
662
Hi,

I am after a vba code that will clear zeros if blank cell found in Col D. So if a blank cell is found in Col D then clear zeros in that row

Excel Workbook
DEFGHIJKLMNOPQR
9Team
10BHP
11RIO
1200000000000000
13TEST1
14TEST2
15TEST3
16TEST4
17TEST5
18TEST6
19TEST7
2000000000000000
21TEST8
22TEST9
23TEST10
24TEST11
2500000000000000
Sheet1
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
For instance:

Code:
Sub clear0whenempty()

    Columns(4).SpecialCells(4).Offset(, 1).EntireRow.Replace 0, "", xlWhole

End Sub

Wigi
 
Upvote 0
Another approach would be... (change to suit)

Rich (BB code):
Sub clearZeros()
Dim Rng As Range, c As Range
    Set Rng = Range("D2:D17")
        For Each c In Rng
            If c = "" Then Range(Cells(c.Row, 5), Cells(c.Row, 18)).ClearContents
        Next c
End Sub
 
Upvote 0
For instance:

Rich (BB code):
Sub clear0whenempty()

    Columns(4).SpecialCells(4).Offset(, 1).EntireRow.Replace 0, "", xlWhole

End Sub

Wigi
Just wondering about the red bit. Is that required?



Another approach would be... (change to suit)

Rich (BB code):
Sub clearZeros()
Dim Rng As Range, c As Range
    Set Rng = Range("D2:D17")
        For Each c In Rng
            If c = "" Then Range(Cells(c.Row, 5), Cells(c.Row, 18)).ClearContents
        Next c
End Sub
Except that this would clear everything in columns E:R of the relavent rows, not just zero values as was requested.
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

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