VBA to return to original active cell after running macro

EssKayKay

Board Regular
Joined
Jan 5, 2003
Messages
233
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

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
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
You are welcome.
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,131
Members
449,097
Latest member
mlckr

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