Replace blank cells with 0

S

scrabtree23

I need a code that will search a range (let's say A1:Z1) and will replace any
blank cells with a zero (0).
 
G

Gord Dibben

If true blanks.............

Sub Zeros()
Dim rng As Range
Set rng = Nothing
On Error Resume Next 'just in case there are no blanks
Set rng = Range("A1:Z1").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If rng Is Nothing Then
'do nothing
Else
rng.Value = 0
End If
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top