VBA to return to original active cell after running macro

EssKayKay

Active Member
Joined
Jan 5, 2003
Messages
407
Office Version
  1. 2007
Platform
  1. Windows
I’m looking for a way to return to cell that was last active prior to running a macro. That is, when a cell in a range (C3:C77) is active, a routine is triggered to test if a cell in that range is “locked”. If it is locked then a Sub is run to “unlock” the range.

I have this working except that after the range has been changed to “unlocked” the range remains highlighted. I can add a Range.Select command at the end of the unlock routine which removes the highlight but then the active cell is not where the user originally placed it but rather the Range.Select cell. After running the unlock routine, I want to return to the original active cell.

Thanks,
Steve
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
First, capture the cell at the very beginning of your code with lines like this:
VBA Code:
Dim c as Range
Set c = ActiveCell

Then at the very end of your code, select that cell you set at the beginning, i.e.
VBA Code:
c.Select
 
Upvote 0
Solution
First, capture the cell at the very beginning of your code with lines like this:
VBA Code:
Dim c as Range
Set c = ActiveCell

Then at the very end of your code, select that cell you set at the beginning, i.e.
VBA Code:
c.Select
Excellent. Thank you Joe - that did.
Much appreciated. . .
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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