Macro that puts "0" into blank cells,

Greg Determann

New Member
Joined
Jan 18, 2005
Messages
20
but if the cell contains a value then to leave it alone. This works for one cell:

If Range("B23") = "" Then Range("B23") = "0"

But I want to check in columns b,d, and f and in rows 17-33 and 80-91 without touching the other cells.

Any ideas? Thanks in advance.
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Here's one way:

<font face=Tahoma><SPAN style="color:#00007F">Sub</SPAN> ZeroBlanks()
<SPAN style="color:#00007F">Dim</SPAN> cell <SPAN style="color:#00007F">As</SPAN> Range, myRange <SPAN style="color:#00007F">As</SPAN> Range

<SPAN style="color:#00007F">Set</SPAN> myRange = Union([B17:B33], [D17:D33], [F17:F33])

<SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> cell <SPAN style="color:#00007F">In</SPAN> myRange
    <SPAN style="color:#00007F">If</SPAN> cell.Value = "" <SPAN style="color:#00007F">Then</SPAN> cell.Value = 0
<SPAN style="color:#00007F">Next</SPAN> cell

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
Can also be done without a macro, eg - Select range, do Edit / Go To / Special / Blanks, type 0 and hit CTRL+ENTER.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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