Unprotect the sheet, do whatever you have to do, protect the sheet. Something like this:

Private Sub CommandButton1_Click()
ActiveSheet.Unprotect Password:="Yourpassword"
With Rows("24:30")
.Select
.EntireRow.Hidden = Not .EntireRow.Hidden
End With
ActiveSheet.Protect Password:="Yourpassword"
End Sub