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 :)
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

CephasOz

Board Regular
Joined
Feb 18, 2020
Messages
196
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,133
Office Version
  1. 365
Platform
  1. Windows
You can simplify that like
VBA Code:
Sub ShowZeros()
   ActiveWindow.DisplayZeros = Not ActiveWindow.DisplayZeros
End Sub
 

husoi

Board Regular
Joined
Sep 12, 2012
Messages
50
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 ;)
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
46,133
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback
 

CephasOz

Board Regular
Joined
Feb 18, 2020
Messages
196
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
That goes for me too.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,701
Messages
5,524,409
Members
409,575
Latest member
navarrov74

This Week's Hot Topics

Top