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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
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>
 

KenWright

Active Member
Joined
Jan 14, 2005
Messages
267
Can also be done without a macro, eg - Select range, do Edit / Go To / Special / Blanks, type 0 and hit CTRL+ENTER.
 

Forum statistics

Threads
1,181,249
Messages
5,928,911
Members
436,634
Latest member
JimHHH

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
Top