Fill in blanks cells with 0

bradyj7

Board Regular
Joined
Mar 2, 2011
Messages
106
Hi there,

Would anyone have a piece of code that would find all blanks in a used range and fill them with zero. The number of columns is fixed (D-G) but the number of rows is variable.

Thank you
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try

Code:
Sub Test2()
Dim LR As Long
LR = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
Range("D1:G" & LR).SpecialCells(xlCellTypeBlanks).Value = 0
End Sub
 
Upvote 0
Do you need code?

1. Select columns D:G by click & drag across the column labels.

2. Ctrl+H|Find what: leave blank|Replace with: 0|Replace All


If you do need code
Code:
Sub FillBlanks()
    On Error Resume Next
    Columns("D:G").SpecialCells(xlCellTypeBlanks).Value = 0
    On Error GoTo 0
End Sub
If you are certain there are going to be blanks, you wouldn't need the two 'On Error' lines
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,510
Members
452,918
Latest member
Davion615

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