If column C to AX is equal to zero, clear contents.
Thanks!!!
If column C to AX is equal to zero, clear contents.
Thanks!!!
Sub test() If WorksheetFunction.Sum(Range("C" & ActiveCell.Row & ":AX" & ActiveCell.Row)) = 0 Then Range("C" & ActiveCell.Row & ":AX" & ActiveCell.Row).ClearContents End If End Sub
It actually run, but zeros were not cleared.
And, why is there a "sum" function?
I just actually want to delete the zeros in the cells. I'm not summing up anything.
Thanks!
Wasn't to sure what you were asking for, here is the code.
Sub test2() For Each c In Range("C" & ActiveCell.Row & ":AX" & ActiveCell.Row) If c.Value = 0 Then c.ClearContents End If Next c End Sub
A non-looping option would be to use Replace:
[VBA]Sub NoZero()
Range("C" & ActiveCell.Row & ":AX" & ActiveCell.Row).Replace _
what:="0", replacement:="", lookat:=xlWhole
End Sub[/VBA]
Thanks!
It worked!
I use this to clear selected areas of zero values
[VBA]
Sub delzero()
For Each cel In Intersect(Selection, ActiveSheet.UsedRange)
If cel.Value = 0 Then cel.ClearContents
Next
End Sub
[/VBA]
and for Error cells
[VBA]Sub DelErrors()
On Error Resume Next
If MsgBox("Clear error cells?", vbYesNo) = vbYes Then
Selection.SpecialCells(xlCellTypeFormulas, 16).ClearContents
Selection.SpecialCells(xlCellTypeConstants, 16).ClearContents
End If
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Thanks again mdmakiilop!