Error with toggle code

H

hmaze

All:

I am using a toggle button to hide/unhide selected rows on different
spreadsheets. The code below works on one sheet but as soon as I move to a
different sheet I get an error message (see ** where error is). Any
suggestions, it's getting stuck at Rows :)8:21").Select - Thank you.

Private Sub ToggleButton1_Click()
Static blflag As Boolean

blflag = Not blflag

If blflag Then
Range("15:16,19:22").Select
Range("A19").Activate
Selection.EntireRow.Hidden = False
Sheets("Spread Analysis").Select
**Rows("8:21").Select
Selection.EntireRow.Hidden = False
Sheets("Client Analysis ").Select
Rows("8:18").Select
Selection.EntireRow.Hidden = False
Sheets("Input Variables").Select
Else
Range("15:16,19:22").Select
Range("A19").Activate
Selection.EntireRow.Hidden = True
Sheets("Spread Analysis").Select
Rows("8:21").Select
Selection.EntireRow.Hidden = True
Sheets("Client Analysis ").Select
Rows("8:18").Select
Selection.EntireRow.Hidden = True
Sheets("Input Variables").Select
End If
End Sub
 
J

Jim Thomlinson

Try this...

Private Sub ToggleButton1_Click()
Static blflag As Boolean

blflag = Not blflag

If blflag Then
Range("15:16,19:22").EntireRow.Hidden = False
Sheets("Spread Analysis").Rows("8:21").EntireRow.Hidden = False
Sheets("Client Analysis ").Rows("8:18").EntireRow.Hidden = False
Else
Range("15:16,19:22").EntireRow.Hidden = True
Sheets("Spread Analysis").Rows("8:21").EntireRow.Hidden = True
Sheets("Client Analysis ").Rows("8:18").EntireRow.Hidden = True
End If
Sheets("Input Variables").Select
End Sub
 
H

hmaze

Jim - that did it - thank you!!!

Jim Thomlinson said:
Try this...

Private Sub ToggleButton1_Click()
Static blflag As Boolean

blflag = Not blflag

If blflag Then
Range("15:16,19:22").EntireRow.Hidden = False
Sheets("Spread Analysis").Rows("8:21").EntireRow.Hidden = False
Sheets("Client Analysis ").Rows("8:18").EntireRow.Hidden = False
Else
Range("15:16,19:22").EntireRow.Hidden = True
Sheets("Spread Analysis").Rows("8:21").EntireRow.Hidden = True
Sheets("Client Analysis ").Rows("8:18").EntireRow.Hidden = True
End If
Sheets("Input Variables").Select
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top