Activate macro on exiting cell (or on a specific cell)

Cath

Board Regular
Joined
Aug 10, 2005
Messages
156
Hi all

I have a macro that should run when I activate a specific cell.

However it runs when I go into ANY cell

My users will enter some data, so ideally I want it to activate when they press enter after putting in the data. I.e they enter data into B5, then C5, and so on entering D5 it should run.

Does that make sense

It should be really simple so I must be making a really obvious mistake

here is my macro

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)

If Target.Address <> "$d$5" Then
MsgBox "got this far"
Application.Run "movedata"
End If

End Sub

Thanks!!

Cath :eek:
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,686
Your IF statement says run the code within the IF BLOCK for any address except $d$5 .... change the <> to =.
 

Cath

Board Regular
Joined
Aug 10, 2005
Messages
156
I had no idea that would make a difference! Thanks a lot its working fine now

Cath :LOL:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,854
Messages
5,833,993
Members
430,250
Latest member
Reggie Mcqueen

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
Top