Clear Contents Value, Move to Next Cell in Column

capo4410

New Member
Joined
Feb 20, 2019
Messages
14
Hello,

I need some help on a macro I am attempting to create. I am completely new to VBA so am struggling a bit with the proper macro to make my desired outcome work. I created a formula in Excel which adds 0s to cells when a condition is met. Ultimately, I need that cell clear of the 0 in order to upload to a website or else an error will occur.

The macro shown below removes the 0 but only in the cell selection. I want the macro to run subsequently in cells down 3 columns, AN, AO, and AP. Any help is much appreciated! Thank you.


Sub DelZeros()
Dim c As Range
For Each c In Selection
If c.Value = 0 Then c.ClearContents
Next c
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
This macro assumes you have headers in row 1 and your data starts in row 2:
Code:
Sub DelZeros()
    Application.ScreenUpdating = False
    Dim LastRow As Long, c As Range
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For Each c In Range("AN2:AP" & LastRow)
        If c.Value = 0 Then c.ClearContents
    Next c
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Wow! Thank you so much, mumps and thanks for such a quick response! This worked perfectly! Could I bother you for another one I'm attempting for the same project? I can add it here, or create a new thread...
 
Upvote 0
Wow! Thank you so much, mumps and thanks for such a quick response! This worked perfectly! Could I bother you for another one I'm attempting for the same project? I can add it here, or create a new thread...
Here is another (slightly different) macro that should also work for you...
Code:
Sub DelZeros()
  With Intersect(Columns("AN:AP"), ActiveSheet.UsedRange)
    .Value = Evaluate("IF(" & .Address & "<>0," & .Address & ","""")")
  End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,187
Members
452,616
Latest member
intern444

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