learning event procedures
There is a good chance in your testing, you experience an error in the event
procedure. At that point, you had
Application.EnableEvents = False
so when the error stopped execution, the events were never turned back on.
Put in a sub in a general module
Sub SetEventsON()
Application.EnableEvents = True
End Sub
then you can turn events back on if you start having problems.
Also, when testing you can put a msgbox command as the first line. Then if
the problem is really a poorly written If statement, you will still know
your event is firing.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
msgbox "In SelectionChange, Target: " & Target.Address(0,0)
'comment-some cells are in bold font
Application.EnableEvents = False
If Target.Font.Bold = True Then
Range("a20").Clear
Range("a20") = 12345
Else
Range("a20").Clear
End If
Application.EnableEvents = True
End Sub
Once you get through debugging your event, you can use error trapping to try
to ensure events are always enabled:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error goto ErrHandler
'comment-some cells are in bold font
Application.EnableEvents = False
If Target.Font.Bold = True Then
Range("a20").Clear
Range("a20") = 12345
Else
Range("a20").Clear
End If
ErrHandler:
Application.EnableEvents = True
End Sub
--
Regards,
Tom Ogilvy
"R.VENKATARAMAN" $$$ wrote in message
...
apologise for asking trivial question.
I have gone through the various instructions in the NG and other pages by
MVPs. still there are many doubts.
this may be a trivial example
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'comment-some cells are in bold font
Application.EnableEvents = False
If Target.Font.Bold = True Then
Range("a20").Clear
Range("a20") = 12345
Else
Range("a20").Clear
End If
Application.EnableEvents = True
End Sub
why does the change of cells not fire the event procedure.
where is my mistake.
If I want to debug at what line should I introduce a breakpoint.(I learnt
it
should be inthe first execuable statement)
when I use the if statment as for example
if target.value 4 etc the event procedure is fired
of course in standard module it works.
thanks and regarads.
|