VBA run macro on cell change - how do I make it execute immediately on change?

Brad B

New Member
Joined
Jul 27, 2016
Messages
17
The macro is executing correctly, but not at the right time.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim KeyCells As Range


' The variable KeyCells contains the cells that will cause an alert when they are changed.
Set KeyCells = Worksheets("PP Master").Range("F8")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then


Worksheets("PP Master").Range("i9").Value = Worksheets("PP Master").Range("f8").Value

End If
End Sub




If I change f8 (via data validation drop down), it doesn't copy the value over until I
1) click away from F8
2) click ON F8.
*Once I click on F8 again (even if I don't change it), the macro runs. I want it to run instantly, the first time I select the new value from the drop down. Suggestions?
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
You might try changing...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

to

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Cheers,

tonyyy
 
Upvote 0
Try removing the text in RED

So you will be using a Change Event macro instead of a SelectionChange Event.

With the Change event when you select from the drop down that will affect a CHANGE to the Target cell.

Howard

Code:
Private Sub Worksheet_[COLOR=#FF0000]Selection[/COLOR]Change(ByVal Target As Range)


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim KeyCells As Range


    ' The variable KeyCells contains the cells that will cause an alert when they are changed.
    Set KeyCells = Worksheets("PP Master").Range("F8")

    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
           Is Nothing Then


        Worksheets("PP Master").Range("i9").Value = Worksheets("PP Master").Range("f8").Value

    End If
 End Sub
 
Upvote 0
You might try changing...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

to

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Cheers,

tonyyy
once again tonyyy to the rescue... I'm still in awe of your help from YEARS ago! :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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