Hiding/Unhiding several lines at the click of a button

  • Thread starter Thread starter Mally
  • Start date Start date
M

Mally

Is there a code i could implement into my sheets to
unhide or hide the same line on several sheets

I want to enter the line number into a cell
Press a button called either 'HIDE' or 'UNHIDE'
The code selects the line number entered in the cell on
all sheets and either hides or unhides them.

Thanks

Mally
 
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Mally,

Here's a simple little routine

Sub HideRows(nRow As Long, Optional Hide As Boolean = True)
Dim sh As Worksheet

For Each sh In Worksheets
sh.Rows(nRow).EntireRow.Hidden = Hide
Next sh

End Sub

example usage

hiderows 10, False

will unhide row 10 on all sheets

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Thanks bob

How can i tell this code to select a cell that contains
the row number that i have entered as a number.

Mally
 
Mally,

Add a commandbutton from the Control Toolbox (you migt need to unhide that
toolbar).
Double-click, this will build a skeleton Command button click event.

Add this code


Private Sub CommandButton1_Click()

If IsNumeric(Range("A1").Value) Then
HideRows Range("A1").Value, Not Rows(Range("A1").Value).Hidden
End If

End Sub

Sub HideRows(nRow As Long, Optional Hide As Boolean = True)
Dim sh As Worksheet

For Each sh In Worksheets
sh.Rows(nRow).EntireRow.Hidden = Hide
Next sh

End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Back
Top