Macro for toggle zero value display

husoi

Board Regular
Joined
Sep 12, 2012
Messages
50
Hello everyone.

Just wanted to share a macro I created that will toggle the display zero values.

It is a very simple code that will change the display of zero values.
I created a button in the ribbon that will access the macro so I just need to press it instead of going to all the trouble (not much I know) to change the zero value being shown or not.

Sub zero_value()
'
' Toggle zero value display Macro
' Macro Created 09/03/2020 by Husoi

If ActiveWindow.DisplayZeros = True Then
ActiveWindow.DisplayZeros = False
Else
ActiveWindow.DisplayZeros = True
End If

End Sub

Enjoy it :)
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hi Husoi. Good stuff - does what you need it to do, and doesn't have any side-effects. Could I make a suggestion, though? When you are doing toggles (flipping a Boolean value from one state to its opposite) a common technique is to use NOT, such as:

VBA Code:
Sub zero_value()
    ActiveWindow.DisplayZeros = Not ActiveWindow.DisplayZeros
End Sub
 
Upvote 0
You can simplify that like
VBA Code:
Sub ShowZeros()
   ActiveWindow.DisplayZeros = Not ActiveWindow.DisplayZeros
End Sub
 
Upvote 0
Cool, guys,

thank you for the info.
This only shows that there is always an easy way..
But I don't go about the easy way isn't ;)
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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