In your words must activate (allow) all the other stuff, but it does not happen things and gives me an error.
I want to tell you that I'm wrong somewhere, but I do not know where.
And so I ask you:
The first macro is you -> works as hidden columns containing zeros.
The second macro (reworked it) to let me hide rows containing zeros.
Each macro itself works.
You're telling me that you have to release all written with an asterisk (') for it to work and so that I can combine them into a single button. But it is not
The first is for the columns and i removed all (') look at it.
The second is revised to rows - there are also removed all (')
Or something wrong?
Sub HidemimiUnhide()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
Sub HidemimitoUnhideRows()
Dim myBTN As Button, cll As Range
With ActiveSheet
Set myBTN = .Buttons(Application.Caller)
If Trim(UCase(myBTN.Caption)) = "HIDE" Then
Application.ScreenUpdating = False
For Each cll In .Range("Num").Cells
cll.EntireRow.Hidden = cll.Value = 0
Next cll
For Each cll In .Range("Num2").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
Else
.Range("Num").EntireRow.Hidden = False
.Range("Num2").EntireRow.Hidden = False
myBTN.Caption = "Hide"
End If
On Error Resume Next
.UsedRange.Cells.SpecialCells(xlCellTypeVisible).EntireRow.AutoFit
On Error GoTo 0
End With
End Sub
I tried in this way, but it gives me an error on this line:
:. Range ("Num2"). EntireRow.Hidden = False 'un-comment i ......................:
Sub mimHidemimiUnhide()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("Num2").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("Num2").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
.UsedRange.Cells.SpecialCells(xlCellTypeVisible).EntireRow.AutoFit
On Error GoTo 0
End With
End Sub