Toggle button - procedure works but elegance needed (xl2007)

K

Kragelund

Hi,

I want to use the toggle button control to alternatively hide and unhide a
selection. My procedure works fine but I am using a linked cell to give a
True or False statement, that the procedure needs. Can the procedure respond
directly to the toggle button being pressed instead? Thx in advance.

the code:

Private Sub ToggleButton1_Click()
Dim SimSheet As Worksheet

Set SimSheet = ActiveSheet
With ActiveSheet
Set ToggleVal = Cells(35, 6)
If ToggleVal = True Then

ActiveSheet.Cells(37, 1).Select
Set tbl = ActiveCell.CurrentRegion
tbl.Resize(tbl.Rows.Count, tbl.Columns.Count).Select
Selection.EntireRow.Hidden = True

Else: Selection.EntireRow.Hidden = False

End If
End With
End Sub
 
S

ShaneDevenshire

Hi,

Yes,

Me.ToggleButton1.Value
or
Me.ToggleButton1
since Value is the default property.

This either returns False or True

If Me.ToggleButton1 = True then
'do something
Else
'do something else
End If

If this helps, please click the Yes button.
 
K

Kragelund

Shane, thanks. I doesn't quite work though. I get the message: expected
procedure, not variable. What am I missing?


Private Sub ToggleButton1_Click()

Me.ToggleButton1
If Me.ToggleButton1 = True Then

ActiveSheet.Cells(37, 1).Select
Set tbl = ActiveCell.CurrentRegion
tbl.Resize(tbl.Rows.Count, tbl.Columns.Count).Select
Selection.EntireRow.Hidden = True

Else: Selection.EntireRow.Hidden = False

End If
End Sub
 
J

JLGWhiz

Your first code line: Me.ToggleButton1

Delete that line. It is meaningless in the context applied.
 

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

Top