PDA

View Full Version : [SOLVED:] Macro show/hide with show/hide zeros in cells



k0st4din
10-21-2013, 10:50 AM
Hello friends
after a long search I managed to find a macro that I need, but now I have another problem. And it is this: In the attached excel file I have cells with zeros in Module 1 I have a macro which hides them in the table. I found another macro that displays the same button (Show / Hide) -> Module 4.
In modul5 trying to do so with the same button so I can hide cells with zeros and displays them.
Ie macro to hide and display works, but how to score (infiltrate) or what to change, that everything works as it should?
10732

k0st4din
10-21-2013, 10:12 PM
You can also offer something different from what I have found.
The idea is that if the order (Total) has result zero to hide the entire column but allows me to hide/show with the same button.
I would be very grateful for assistance from you.
If there is anything unclear please ask.

p45cal
10-22-2013, 01:36 AM
try (and see comments in the code):
Sub HideUnhide()
Dim myBTN As Button, cll As Range

With ActiveSheet
Set myBTN = .Buttons(Application.Caller)
If Trim(UCase(myBTN.Caption)) = "HIDE" Then 'the caption on the button is what decides whether to show or hide.
'Application.ScreenUpdating = False 'optional to stop screen flicker.
For Each cll In .Range("Sum").Cells
cll.EntireColumn.Hidden = cll.Value = 0
Next cll
' For Each cll In .Range("Sum2").Cells 'un-comment these three lines to hide zero rows too.
' cll.EntireRow.Hidden = cll.Value = 0
' Next cll
myBTN.Caption = "Show"
'Application.ScreenUpdating = True 'REQUIRED!!!! if you've enabled the line Application.ScreenUpdating = False above.
Else
.Range("Sum").EntireColumn.Hidden = False
'.Range("Sum2").EntireRow.Hidden = False'un-comment if you've un-commented the row-hiding lines above (it shows the rows).
myBTN.Caption = "Hide"
End If
On Error Resume Next
.UsedRange.Cells.SpecialCells(xlCellTypeVisible).EntireColumn.AutoFit
On Error GoTo 0
End With
End Sub

k0st4din
10-22-2013, 02:04 AM
Thank you very much.
Will do a perfect job. This is exactly what I was looking for, but did not know how to do it.
You're all perfect. :bow: