Hiding Rows

D

~Danny~

I'd like to have a toggle button on a sheet that
alternately hides and unhides a number of rows, say 5:10
Anyone know how?
I keep getting the error "Unable to set the Hidden
property of the range class"

The sheet is protected, userinterfaceonly:= true and
enableselection = xlunlocked cells

Many thanks
 
R

Ron de Bruin

Try this

Sub test()
With ActiveSheet
If .Rows("5:10").EntireRow.Hidden = True Then
.Rows("5:10").EntireRow.Hidden = False
Else
.Rows("5:10").EntireRow.Hidden = True
End If
End With
End Sub
 
T

Tom Ogilvy

Private Sub CommandButton1_Click()
Me.Protect UserInterfaceOnly:=True
Me.EnableSelection = xlUnlockedCells
Rows("5:10").Hidden = Not Rows("5:10").Hidden
End Sub

worked fine for me in Excel 2000. If you have Excel 97, change the
takefocusonclick property to false.
 
I

IC

You may also need to unprotect/protect the sheet.

Sub test()
Worksheets(1).Unprotect
' Ron's code
Worksheets(1).Protect
End Sub

Ian
 
R

Ron de Bruin

The sheet is protected, userinterfaceonly:= true

The OP already protect it with userinterfaceonly:= true
The macro should run correct
 
Top