Fill a Blank Range with Zeros
The need to fill a blank range with zeros often occurs when dealing with data that is downloaded from a mainframe. Recently I've seen several examples that utilize a loop structure to fill a blank range with zeros. Rather than using loops, below is an example that utilizes the SpecialCells method to fill a range.
Sub FillBlanksWithZeros()
Dim Rng As Range
On Error GoTo ErrHandler
Set Rng = Range("A1:B10")
Rng.SpecialCells(xlCellTypeBlanks) = 0
Exit Sub
ErrHandler:
MsgBox "Error # " & Err.Number & " - " & Err.Description
End Sub
The SpecialCells method is much faster than using a loop structure.
Comments
Comment Form