Need help with ClearContents

MPFraser7

New Member
Joined
Dec 14, 2016
Messages
34
Hello,

I am trying to show blank cells instead of 0 for the whole worksheet.

Here is what I've come up with:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
For Each cell In SomeRange
If (cell.Value = 0) Then cell.ClearContents
Next
End Sub

How do I get this to work?

Thanks!
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
try:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

For Each cell In UsedRange
If (cell.Value = 0) Then cell.ClearContents
Next
End Sub
NOTE that this macro will run EVERY time you select a new cell. If you only need this to run once, delete the macro afterwards or put it in a module and assign it to a button...
 
Upvote 0
Do you really need to do this every time you move to a different cell on your sheet?

That's what selection change is all about.
 
Upvote 0
You can do this without using code. Here is the procedure for XL2010 (it will be similar, but maybe not exact, in other versions. Bring up the "Excel Options" dialog (File tab, Options item), select "Advanced" in the left-hand list, scroll down to where it says "Display options for this worksheet" and uncheck the Checkbox labeled "Show a zero in cells that have zero value", click "OK" to finish.
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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