Run macro based on previously selected cell

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
358
Office Version
  1. 2007
Platform
  1. Windows
Hello,

I’m looking for a VBA routine to run a macro if the previous selected cell was “K7”. I may be wrong but I assume this code will be placed in the Worksheet_SelectionChange subroutine. Any suggestions would be appreciated.

Thanks for viewing,
Steve K.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Sadly, there doesn't seem to be a "BeforeSelectionChange" event, so yes, SelectionChange would be the only one you could use. However, this event will not tell you what cell was active, but will only tell you what your selection became. You could set a module level variable in a standard module to the cell address at the end of this event, but that will only happen after the first selection change. To get around that, you'd probably have to get the active cell address when the workbook opens in order to have a starting address at that time. If that happens to be K7, then what?

However, the active cell pertains to the active sheet, so if you're wanting to work with Sheet2 but the wb opens and Sheet1 happens to be the active sheet, and K7 is the active cell, then that could be a problem. If the sheet name matters you'd need to incorporate the sheet name into the variable as well. I guess I'm rambling a bit because you didn't say if it was one sheet or every sheet that you want this to work for. Hopefully you get my drift.
 
Upvote 0
Thank you Micron for your insight. I will probably just leave things as is.
Steve
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,173
Members
451,543
Latest member
cesymcox

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