worksheet change event

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,074
Office Version
  1. 2019
Platform
  1. Windows
I'm using the code below to change the font colors of cells that have constant values (works well). However, I notice the code triggers a worksheet change event, which I'm puzzled as to why this code triggers a worksheet change event?

VBA Code:
Cells(ActiveCell.Row, 20).Resize(, 49).SpecialCells(xlConstants).Font.Color = RGB(14, 33, 56)
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
That line will not trigger a change event, what else is in the same procedure?
 
Upvote 0
I step debugged through the code and sure enough, its trriggering it... the rest of the code. I added the application.enableevents to stop the trigger.

VBA Code:
If cbEnter.Caption = "Enter" Then
    Application.EnableEvents = False
    If Wks.Shapes("Position").TextFrame.Characters.Text = "Dark" Then
        Cells(ActiveCell.Row, 20).Resize(, 49).SpecialCells(xlConstants).Font.Color = RGB(14, 33, 56)
    Else
        Cells(ActiveCell.Row, 20).Resize(, 49).SpecialCells(xlConstants).Font.Color = RGB(255, 255, 255)
    End If
    Application.EnableEvents = True
    MsgBox "Transaction Recorded!", vbInformation
 
Upvote 0
That does trigger a change event for me, are you sure it's that line?
 
Upvote 0
Because of this line
VBA Code:
Application.EnableEvents = False
that line cannot trigger the change event.
 
Upvote 0
When you step through, does it switch to the change_event after the line that you say, or at a different point?
 
Upvote 0
I just did another entry from my userform to enter the data in the sheet. I started to debug at if cbEnter.Caption = "Enter" and step through it and as soon as it came across
Cells(ActiveCell.Row, 20).Resize(, 49).SpecialCells(xlConstants).Font.Color = RGB(255, 255, 255), it switch to the worksheet change event. (this is without the enable events)
 
Upvote 0
I mis-spoke. It was triggering a worksheet selection event (not worksheet change event)..sorry.

Anywas, why?
 
Upvote 0
That line will not trigger a selection change either (with or without disabling events)
 
Upvote 0
I mis-spoke. It was triggering a worksheet selection event (not worksheet change event)..sorry.

Anywas, why?
If you step through your code line-by-line, using the F8 key, you can see exactly when it jumps to your Worksheet_SelectionChange event procedure.
Make note of the last line of code run before it goes to the Worksheet_SelectionChange event procedure.
That is the line of code that is triggering it.
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,611
Members
449,109
Latest member
Sebas8956

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