WorkSheet_Change and/or WorkSheet_SelectionChange Not being Fired

Ronaldj

New Member
Joined
May 10, 2024
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I have put the following code in Sheet1 (right click code) or This Workbook Code or Modules - Module 1 and in none of these cases did it run in response to selection or value changes entered on the workbook spread sheet. I checked (Immediate window) that Application.EnableEvents is true. I closed the Excel, rebooted and still it doesn't work. Using EXCEL365 on Windows 11 Have spent many hours going round and round this. Any insights will be appreciated.
Option Explicit
Sub WorkSheett_Change(ByVal Terget As Range)
Application.EnableEvents = False
If Target.Address = "D1" Then
MsgBox ("GotIt")
Else
MsgBox ("Not It")
End If
Application.EnableEvents = True
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the Board!

You have multiple typos in your first line:
Rich (BB code):
Sub WorkSheett_Change(ByVal Terget As Range)
should be:
Rich (BB code):
Sub WorkSheet_Change(ByVal Target As Range)

And all "Worksheet_Change" event procedure code needs to go in the Sheet module of the particular sheet you want it to run against.
 
Upvote 0
Joe's comments have addressed why it is not firing. Another issue is that address will return $D$1 not D1 so your if statement will return false.
VBA Code:
Sub WorkSheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$D$1" Then
        MsgBox ("GotIt")
    Else
        MsgBox ("Not It")
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Joe's comments have addressed why it is not firing. Another issue is that address will return $D$1 not D1 so your if statement will return false.
VBA Code:
Sub WorkSheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$D$1" Then
        MsgBox ("GotIt")
    Else
        MsgBox ("Not It")
    End If
    Application.EnableEvents = True
End Sub
Nice catch, Alex!
 
Upvote 0
Joe's comments have addressed why it is not firing. Another issue is that address will return $D$1 not D1 so your if statement will return false.
VBA Code:
Sub WorkSheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$D$1" Then
        MsgBox ("GotIt")
    Else
        MsgBox ("Not It")
    End If
    Application.EnableEvents = True
End Sub
Many (Humble) thanks. Apologies for the nuisance due to my Old (84) bad eyes. Guess I need a larger Monitor !
So, in my application I auto generate multiple Sheets with their common code in Modules and each Sheet with its own data.
I will need to find a way to populate the replicated Sheet's code with this same WorkSheetChange code. Hmmm ? !
 
Upvote 0
If you put your code in the "Workbook_SheetChange" event in the "ThisWorkbook" module (as opposed to the underlying sheet modules), it will apply to ALL sheets of your workbook, no matter how many there are or when you add them, i.e.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$D$1" Then
        MsgBox ("GotIt")
    Else
        MsgBox ("Not It")
    End If
    Application.EnableEvents = True
End Sub
 
Upvote 0
Many (Humble) thanks. Apologies for the nuisance due to my Old (84) bad eyes. Guess I need a larger Monitor !
So, in my application I auto generate multiple Sheets with their common code in Modules and each Sheet with its own data.
I will need to find a way to populate the replicated Sheet's code with this same WorkSheetChange code. Hmmm ? !

If you put your code in the "Workbook_SheetChange" event in the "ThisWorkbook" module (as opposed to the underlying sheet modules), it will apply to ALL sheets of your workbook, no matter how many there are or when you add them, i.e.
VBA Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    Application.EnableEvents = False
    If Target.Address = "$D$1" Then
        MsgBox ("GotIt")
    Else
        MsgBox ("Not It")
    End If
    Application.EnableEvents = True
End Sub
Great, thanks. I imagine I can use sh.Name to avoid Sheets I don't want it to touch.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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