SelectionChange stopped working

Dav1d

New Member
Joined
Sep 27, 2010
Messages
27
The code below created a new line below when a cell in column F was changed (a dropdown menu). I'm certain it was working perfectly but now it isn't.

Can someone anyone see a problem with the code, please?


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Unprotect
If Target.Count > 1 Then Exit Sub
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("F:F")) Is Nothing Then
Target.Offset(1).EntireRow.Insert
Target.EntireRow.Copy Target.Offset(1).EntireRow
On Error Resume Next
Target.Offset(1).EntireRow.SpecialCells(xlConstants).ClearContents
ActiveSheet.Protect AllowDeletingRows:=True
On Error GoTo 0
End If
Application.EnableEvents = True
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Your code runs when you select a different cell, not when you change a cell.
 
Upvote 0
Hi Rory

Thanks for the rapid [immediate!] reply, I really appreciate your time.

The macro doesn't fire even when I move out of the F column. Nothing happens.

(The security level is generally set medium but at low it doesn't either).
 
Upvote 0
The code only fires if you select a cell in column F. If it's still not firing, have you had any error messages?
 
Upvote 0
You probably interrupted your code one time, and it didn't get to the line
Application.EnableEvents = True

You need to put that in the immediate window and press enter, so that it is again enabled.
 
Upvote 0
Sorry, Hermanito, I'd typed the reply but didn't hit send. One of those mornings.

Yes, I tried that. I even retyped the whole macro as a start again approach but no difference.
 
Upvote 0
try setting a breakpoint on the first line of code inside the eventhandler.
Then go in your worksheet and perform the action that should trigger the event... if you don't get thrown into the code in debugmode, it means your events are still disabled somehow...
Otherwise you can step through the rest of the code and check why it doesn't work as expected...

Have you tried closing and reopening Excel?
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,855
Members
452,948
Latest member
UsmanAli786

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