Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default learning event procedures

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.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default learning event procedures

The procedure works for me - XL2000, winXP.
Mike F
"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.






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default learning event procedures

Did you put the code in a worksheet module? It won't fire unless it is in
such a module.

--
HTH

Bob Phillips

"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.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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.






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default learning event procedures

thank all of you MVPs for giving me some idea. I would test the seteventson
sub for debugging.

In the meanwhile I found my mistake. I did go the worksheet code by
rightclicking sheet tab and clicking view code. therein I must have
forgotten to click the worksheet and the code statements were wrongly
originally parked under <general. when I cut and paste the statements
under worksheet it works fine. sorry for the trouble. I was misled because
the stataements were threre both under general and worksheet.

for debugging I will follow the seteventon sub given by Mr. Togilvy;.

I got some(only some) of the cobwebs cleared. I am still on learning curve


thanks and regarads.




Tom Ogilvy wrote in message
...
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.












Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event procedures (and the temple of doom) Mark Tangard[_3_] Excel Programming 2 July 20th 04 04:45 PM
problems with Add-In event procedures when moving WB files between computers jon Excel Programming 2 April 29th 04 04:47 PM
Event Procedures: Event on Worksheet to fire Event on another Worksheet Kathryn Excel Programming 2 April 7th 04 07:35 PM
Passing ARGUMENTS between event procedures of a USERFORM jason Excel Programming 8 November 10th 03 07:36 PM
Creating Event procedures from a macro Robert Stober Excel Programming 3 September 7th 03 06:52 PM


All times are GMT +1. The time now is 02:52 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"