View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 692
Default Event macro firing twice

Your code may be activating events (I am not sure)
but you can prevent that by wrapping your code -

Application.EnableEvents=False
' your code

Application.EnableEvents=True

--
steveB

Remove "AYN" from email to respond
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
Tom Ogilvy, Vasant, and Greg Wilson were very helpful with setting up my
code. The objective was to determine which one of many checkboxes was
clicked on and its value. I am having one problem with it and I think
it's due to some code that I added.
The event macro, in a class module, is:
Public WithEvents CheckBoxGroup As MSForms.CheckBox
Private Sub CheckBoxGroup_Click()
Set i = ActiveSheet.Range(CheckBoxGroup.LinkedCell)
MsgBox CheckBoxGroup.Name & " clicked"
Call CopyData2
End Sub

The line above that starts with "Set i = " is mine. I want to set "i" to
the cell that is linked to the checkbox that was clicked on. My final
purpose is to access the cell to the right of that linked cell.
I reduced my code in the CopyData2 macro to just a few lines to
demonstrate my problem. The CopyData2 macro is:
Sub CopyData2()
Set Dest = Sheets("Results").Range("D1")
i.Offset(, 1).Copy
Dest.PasteSpecial xlPasteValues
End Sub

My problem is that the event macro fires twice when the checkbox is
clicked to True once. This of course causes the CopyData2 macro to
execute twice as well.
Where did I go wrong? Thanks for your help. Otto