Toggle Button oddity

D

Dallman Ross

I've constructed a simple toggle button to hide or unhide some
sheets. (I used a bit of the code contributed by Dave Peterson in
a related macro project I'm working on.) The button works fine.

But there's one oddity: if I click it twice, i.e., on and then
off, it then stops working until I click focus somewhere other
than the button. Then I can click on it again and it works for
another two times.

I can't figure out why. I have a very similar button that doesn't
stop working like that after two clicks. In fact, I copied the
first button to start out my coding for this one.

Any bright ideas?

--------------------------------------------
Private Sub ToggleButton2_Click()

Dim iCtr As Long
Dim wksNames As Variant
wksNames = Array("2006 Realized - CSV Data", _
"Current - CSV Data", "Symbol Lookup")

Application.ScreenUpdating = False

For iCtr = LBound(wksNames) To UBound(wksNames)
With Worksheets(wksNames(iCtr))
.Visible = ToggleButton2.Value
End With
Next iCtr

Application.ScreenUpdating = True
End Sub
 
G

Guest

I couldn't duplicate your issue. You code worked perfectly for me no matter
how many times I clicked the toggle nor how fast I clicked it.
Sorry,
--
HTH,
Gary Brown
(e-mail address removed)
If this post was helpful to you, please select ''YES'' at the bottom of the
post.
 
D

Dave Peterson

I couldn't reproduce the problem, either:

But maybe activating a cell will help:

Option Explicit
Private Sub ToggleButton2_Click()
Dim iCtr As Long
Dim wksNames As Variant

ActiveCell.Activate

'rest of code
 
D

Dallman Ross

Dave Peterson said:
I couldn't reproduce the problem, either:

But maybe activating a cell will help:

Option Explicit
Private Sub ToggleButton2_Click()
Dim iCtr As Long
Dim wksNames As Variant

ActiveCell.Activate

'rest of code

That works!! Thanks ever so much, Dave.

-dman-

========================================================================
 

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