Macro to clear Zeroes in Col A to C

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,585
Office Version
  1. 2021
Platform
  1. Windows
I have written code to clear zeroes in Col A to C

I get a type mismatch when running the code and the following code is highlighted

Code:
 If .Cells(i, 1).Resize(, 2) = 0 Then


See full code below



Code:
 Sub clear_Zero_Values()
     With Sheets(1)
   Dim lr As Long
Dim i As Long

  lr = .Cells(.Rows.Count, "A").End(xlUp).Row
  For i = lr To 1 Step -1
    If .Cells(i, 1).Resize(, 2) = 0 Then
      Cells(i, 1).Resize(, 2).ClearContents
    End If
  Next i
  End With
  
End Sub


It would be appreciated if someone could amend my code
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hello,

If you are dealing exclusively with constants ...

Code:
Sub TestConstants()
    Columns("A:C").SpecialCells(xlCellTypeConstants, 23).ClearContents
End Sub

HTH
 
Last edited:
Upvote 0
otherwise try...
Code:
Sub clear_Zero_Values()
    Dim lr As Long, cel As Range
    With Sheets(1)
        lr = .Cells(.Rows.Count, "A").End(xlUp).Row
        For Each cel In .Range("A1:C" & lr)
            If cel = 0 Then cel.ClearContents
        Next cel
    End With
End Sub
 
Last edited:
Upvote 0
Why not use the usual replace box (Ctrl+H)?
 
Upvote 0
Hi Guys


Thanks for the help, much apreciated
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,399
Latest member
alchavar

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