Macro to clear Zeroes in Col A to C

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
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

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
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

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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