worksheet_change event fires multiple times

  • Thread starter Thread starter timconstan
  • Start date Start date
T

timconstan

I have a cell formated as "h:mm AM/PM". If the user doesn't enter
valid time, they get an error message. If they don't enter a vali
time again, they keep getting the error message until the press Cancel
or enter a valid time.

I'm keeping track of the changes on the spreadsheet using th
worksheet_change event.

When the user enters a valid time the worksheet_change event fires.

If the user had entered an invalid time 2 times, then finally enters
valid time, the worksheet_change event fires 3 times.

Is there an event that would only fire when the user has entered
valid time, and only fire once
 
If your change event is firing multiple time then your on change event must
be making a change itself. (recursive call) To fix this at the beginning of
the on change event add this

application.enableevents = false

and at the end

application.enableevents = true

when you use code like this it is a good idea to include error handling
which turns events back on in case of an error

Top of sub

On Error Goto ErrorHandler

Bottom of sub

exit sub
ErrorHandler:
application.enableevents = true
application.screenupdating = true
end sub

Hope this helps...
 

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

Back
Top