Enable Events Issue

brenner

Board Regular
Joined
Sep 13, 2007
Messages
96
The procedure below is called within all of my other procedures, including event procedures (worksheet change and worksheet selection change). Stepping through the code, the procedure the following line evaluates to true (Trim(Range("Rationale").Item(1).Text) <> "" And Trim(Range("Rationale").Item(1).Text) <> Rationale1 And Trim(Range("Rationale").Item(1).Text) <> PMRationale2). The code executes the setting events to false and colors the cell, but it doesn't execute the next line and instead jumps back to the next line following where this procedure was called. As a result, my events are never re-enabled.


Sub Rationale(Optional ListedChange As Boolean)

If ListedChange Then
If Range("IsListed") = "Yes" Then
bBypassSelectChange = True
Application.EnableEvents = False
Range("Rationale") = Rationale1
Range("Rationale").Interior.ColorIndex = ReqColorIdx
Application.EnableEvents = True
ElseIf Range("IsListed") = "No" Then
bBypassSelectChange = True
Application.EnableEvents = False
Range("Rationale") = Rationale2
Range("Rationale").Interior.ColorIndex = ReqColorIdx
Application.EnableEvents = True
Else
bBypassSelectChange = True
Application.EnableEvents = False
Range("Rationale").ClearContents
Range("Rationale").Interior.ColorIndex = ReqColorIdx
Application.EnableEvents = True
End If
Else
If Trim(Range("Rationale").Item(1).Text) <> "" And Trim(Range("Rationale").Item(1).Text) <> Rationale1 And Trim(Range("Rationale").Item(1).Text) <> Rationale2 Then
Application.EnableEvents = False
Range("Rationale").Interior.ColorIndex = StdColorIdx
Application.EnableEvents = True
Else
Call Rationale(True)
End If
End If
End Sub
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
without fully understanding your code, try setting EnableEvents from the calling procedure e.g.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Application.EnableEvents = False
 Rationale True
 Application.EnableEvents = True
End Sub
 
Sub Rationale(Optional ListedChange As Boolean)
'rest of code
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top