Hi all,
I have a macro which hides all rows in a column within my specific spreadsheet as per the ranges used.
I would like to set my macro up to toggle between hiding and then unhiding so need something to reverse the process.
The following is the code I have used:
Sub HideUnusedRows()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 127
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, "C").Value) Then
'Do nothing, This avoid a error if there is a error in the cell
ElseIf .Cells(Lrow, "C").Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "C")
Else
Set rng = Application.Union(rng, .Cells(Lrow, "C"))
End If
End If
Next
End With
'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
I appreciate any help.
Kind regards,
Sean
I have a macro which hides all rows in a column within my specific spreadsheet as per the ranges used.
I would like to set my macro up to toggle between hiding and then unhiding so need something to reverse the process.
The following is the code I have used:
Sub HideUnusedRows()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
Dim rng As Range
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.DisplayPageBreaks = False
StartRow = 6
EndRow = 127
For Lrow = StartRow To EndRow Step 1
If IsError(.Cells(Lrow, "C").Value) Then
'Do nothing, This avoid a error if there is a error in the cell
ElseIf .Cells(Lrow, "C").Value = "0" Then
If rng Is Nothing Then
Set rng = .Cells(Lrow, "C")
Else
Set rng = Application.Union(rng, .Cells(Lrow, "C"))
End If
End If
Next
End With
'hide all rows in one time
If Not rng Is Nothing Then rng.EntireRow.Hidden = True
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
I appreciate any help.
Kind regards,
Sean