ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Need to Use 1 Button to toggle On or Off (https://www.excelbanter.com/excel-discussion-misc-queries/168110-need-use-1-button-toggle-off.html)

Jim May

Need to Use 1 Button to toggle On or Off
 
This works perfectly:

Sub HideZeroRows()
'to hide calculated items that equal zero
'hide worksheet rows that contain zeros
'by John Green
Dim rRow As Range
Application.ScreenUpdating = False
For Each rRow In ActiveSheet _
.PivotTables(1).DataBodyRange.Rows
If Application.Sum(rRow) = 0 Then
rRow.EntireRow.Hidden = True
End If
Next rRow
Application.ScreenUpdating = True
End Sub

There is a Macro that will **If no rows are
hidden - Run the Macro and If Rows Are hidden
UnHide All Rows. But how is this done?
Any assistance appreciated..


Gary''s Student

Need to Use 1 Button to toggle On or Off
 
Include this line:

Rows.Hidden = False

It will unhide all rows
--
Gary''s Student - gsnu200759


"Jim May" wrote:

This works perfectly:

Sub HideZeroRows()
'to hide calculated items that equal zero
'hide worksheet rows that contain zeros
'by John Green
Dim rRow As Range
Application.ScreenUpdating = False
For Each rRow In ActiveSheet _
.PivotTables(1).DataBodyRange.Rows
If Application.Sum(rRow) = 0 Then
rRow.EntireRow.Hidden = True
End If
Next rRow
Application.ScreenUpdating = True
End Sub

There is a Macro that will **If no rows are
hidden - Run the Macro and If Rows Are hidden
UnHide All Rows. But how is this done?
Any assistance appreciated..


Jim May

Need to Use 1 Button to toggle On or Off
 
Gary's Student : Thanks, but I do not know how to use what you are suggesting.

So far I have the following: (Which is not working) - It call my Macro

Sub HideUnHideRow() ' This is my Toggle Macro attached to a forms button
Dim bHidden As Boolean
If ActiveSheet.Cells.EntireRow.Hidden = False Then
HideZeroRows ' The Main Macro
bHidden = True
Else
ActiveSheet.Cells.EntireRow.Hidden = True
End If
bHidden = Not bHidden
End Sub


"Gary''s Student" wrote:

Include this line:

Rows.Hidden = False

It will unhide all rows
--
Gary''s Student - gsnu200759


"Jim May" wrote:

This works perfectly:

Sub HideZeroRows()
'to hide calculated items that equal zero
'hide worksheet rows that contain zeros
'by John Green
Dim rRow As Range
Application.ScreenUpdating = False
For Each rRow In ActiveSheet _
.PivotTables(1).DataBodyRange.Rows
If Application.Sum(rRow) = 0 Then
rRow.EntireRow.Hidden = True
End If
Next rRow
Application.ScreenUpdating = True
End Sub

There is a Macro that will **If no rows are
hidden - Run the Macro and If Rows Are hidden
UnHide All Rows. But how is this done?
Any assistance appreciated..



All times are GMT +1. The time now is 02:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com