Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Worksheet_Change Event Strange Behaviour

Hi,

I have been cracking my head to solve this problem for few days to no avail.
hopefully someone can help me.
I have 1 cell with drop down list, when the user enter a value that is not
in the list, they'll get an error (set from Data Validation). If they enter a
correct value, the message will be displayed from Worksheet_Change event
below.

It's all fine if they always enter the correct value but when they enter the
wrong value and correct it afterwards (Excel will ask if they want to try
again), the Worksheet_Change event will run twice. When the user enter the
wrong value twice, the event will run 4 times (it doubles the number).


Private Sub Worksheet_Change(ByVal Target As Range)
Dim c
Dim x
Dim rng As Range
Dim vRow As Double
Dim sPrn As String
Dim currCell As Range
'Dim OldVal
Dim lngFound

On Error GoTo errWorksheet_Change
With Target
If .Count = 1 Then
'Change printer
If Not Intersect(.Cells, Range("C5")) Is Nothing Then
Application.EnableEvents = False
If .Cells < "" Then
Application.ActivePrinter =
Worksheets("Main").Cells(rowPrinter, 3).Value & " on LPT1:"
MsgBox Application.ActivePrinter & " is activated!"
Else
MsgBox "No barcode printer is available!"
End If
Application.EnableEvents = True
End If
continue......
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Worksheet_Change Event Strange Behaviour

Hi
is Application.EnableEvents = True in the right place? Is the code
below it firing the change event?
regards
Paul

On Feb 27, 10:06*am, Sugih wrote:
Hi,

I have been cracking my head to solve this problem for few days to no avail.
hopefully someone can help me.
I have 1 cell with drop down list, when the user enter a value that is not
in the list, they'll get an error (set from Data Validation). If they enter a
correct value, the message will be displayed from Worksheet_Change event
below.

It's all fine if they always enter the correct value but when they enter the
wrong value and correct it afterwards *(Excel will ask if they want to try
again), the Worksheet_Change event will run twice. When the user enter the
wrong value twice, the event will run 4 times (it doubles the number).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c
Dim x
Dim rng As Range
Dim vRow As Double
Dim sPrn As String
Dim currCell As Range
'Dim OldVal
Dim lngFound

On Error GoTo errWorksheet_Change
With Target
* * If .Count = 1 Then
* * * * 'Change printer
* * * * If Not Intersect(.Cells, Range("C5")) Is Nothing Then
* * * * * * Application.EnableEvents = False
* * * * * * If .Cells < "" Then
* * * * * * * * Application.ActivePrinter =
Worksheets("Main").Cells(rowPrinter, 3).Value & " on LPT1:"
* * * * * * * * MsgBox Application.ActivePrinter & " is activated!"
* * * * * * Else
* * * * * * * * MsgBox "No barcode printer is available!"
* * * * * * End If
* * * * * * Application.EnableEvents = True
* * * * End If
continue......


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Worksheet_Change Event Strange Behaviour

Hi Paul,

Thanks for responding to my post.
The code below it will be for different cells, I don't want to post it
because it would be too long but basically is another set of below statement.

If Not Intersect(.Cells, Range(xxx)) Is Nothing Then
End If

At the end of the sub there will be this code.


End If 'to close If Count = 1 statement
End With
Exit Sub

errWorksheet_Change:
Application.EnableEvents = True
MsgBox "An error has occured, please contact your system
administrator.", , "Error."

End Sub
Thanks,
Sugih

" wrote:

Hi
is Application.EnableEvents = True in the right place? Is the code
below it firing the change event?
regards
Paul

On Feb 27, 10:06 am, Sugih wrote:
Hi,

I have been cracking my head to solve this problem for few days to no avail.
hopefully someone can help me.
I have 1 cell with drop down list, when the user enter a value that is not
in the list, they'll get an error (set from Data Validation). If they enter a
correct value, the message will be displayed from Worksheet_Change event
below.

It's all fine if they always enter the correct value but when they enter the
wrong value and correct it afterwards (Excel will ask if they want to try
again), the Worksheet_Change event will run twice. When the user enter the
wrong value twice, the event will run 4 times (it doubles the number).

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c
Dim x
Dim rng As Range
Dim vRow As Double
Dim sPrn As String
Dim currCell As Range
'Dim OldVal
Dim lngFound

On Error GoTo errWorksheet_Change
With Target
If .Count = 1 Then
'Change printer
If Not Intersect(.Cells, Range("C5")) Is Nothing Then
Application.EnableEvents = False
If .Cells < "" Then
Application.ActivePrinter =
Worksheets("Main").Cells(rowPrinter, 3).Value & " on LPT1:"
MsgBox Application.ActivePrinter & " is activated!"
Else
MsgBox "No barcode printer is available!"
End If
Application.EnableEvents = True
End If
continue......



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
Strange if(***) behaviour? Excel 2003 - SPB Excel Discussion (Misc queries) 6 August 6th 06 05:34 PM
Strange VBA Behaviour Ricko Excel Programming 0 July 28th 05 07:53 AM
Strange behaviour Edgar Thoemmes Excel Worksheet Functions 1 February 8th 05 03:20 PM
Strange behaviour in VBA Help Michael Singmin Excel Programming 4 June 4th 04 07:06 PM
strange behaviour Patrick Molloy Excel Programming 0 September 4th 03 07:51 AM


All times are GMT +1. The time now is 08:51 AM.

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

About Us

"It's about Microsoft Excel"