Private Sub Worksheet_SelectionChange() doesn't run

filipovbf

New Member
Joined
Jul 17, 2017
Messages
5
Hallo!
I have the problem with running the code shown below.
This code is written in Sheet2.
The cell range "MyRange" is in Sheet2, and the macro "MyMAcro" is in module1 of VBA.
When I change any cell value in "MyRange" the code doesn't run.
Any Help?
Thanks in advance!
Bobby


Excel1.jpg
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
When I change any cell value in "MyRange" the code doesn't run.
If you want it to run when you change a cell in MyRange then you want
Private Sub Worksheet_Change(ByVal Target As Range)
not
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
Upvote 0
If you want it to run when you change a cell in MyRange then you want
Private Sub Worksheet_Change(ByVal Target As Range)
not
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Thank you Peter! I changed with "Private Sub Worksheet_Change(ByVal Target As Range)", but nothing happends.
 
Upvote 0
Are you changing values in MyRange manually or are the changes the results of formulas?
 
Upvote 0
At some point enable events maybe false, maybe your code turned it off and didn't turn back on if

Goto immediate window and type
?application.enableevents
 
Upvote 0
Are you changing values in MyRange manually or are the changes the results of formulas?
Thanks of all who wanted to help me, but it seems the problem have been very simple. After I changed
"Private Sub Worksheet_SelectionChange(ByVal Target As Range)"
with
"Private Sub Worksheet_Change(ByVal Target As Range):
and nothing happened, I just restarted Excel and my code start to work.
Thanks one time more!!
 
Upvote 0
Thanks of all who wanted to help me, but it seems the problem have been very simple. After I changed
"Private Sub Worksheet_SelectionChange(ByVal Target As Range)"
with
"Private Sub Worksheet_Change(ByVal Target As Range):
and nothing happened, I just restarted Excel and my code start to work.
Thanks one time more!!
That tends to support @uk747's line of thinking.
The suggestion there was to see if EnableEvents was turned on or off in the immediate window by entering.
(the question mark is the equivalent to "print to the immediate window")
VBA Code:
? Application.EnableEvents

After the code crashes it is often the case that settings turned off don't get turned back on again.
You could go straight to trying to turning it back on with the below in the immediate window.
VBA Code:
Application.EnableEvents = True
Reopening the workbook also resets these settings

If you don't have the immediate window visible Ctrl+G while in the VBA window will make it visible.
 
Upvote 0

Forum statistics

Threads
1,214,922
Messages
6,122,281
Members
449,075
Latest member
staticfluids

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