Returning to initial cell after macro runs

blk

Board Regular
Joined
May 27, 2003
Messages
61
Hi,

This is probably easy, but I can't work it out.

I have a macro that while running, it is necessary to select cells, due to paste special values.

How can I get excel to remember what cell or range was active at the start of the macro, and then return to the same cell or range at the end.

Thanks


Ben
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this;

Code:
Dim mysheet
Dim mycell
mysheet = ActiveSheet.Name
mycell = ActiveCell.Address

'your code here

Sheets(mysheet).Range(mycell).Select
 
Upvote 0
There are very few reasons to 'go' places in a macro. PasteSpecial is not one of them. See the code I posted in your other discussion on how to convert all values in a range to upper case. That code did not 'go' anywhere to accomplish the task.

For more on how to eliminate 'activate's and 'select's, check the Excel | VBA | 'Beyond Excel's recorder' page of my web site.
blk said:
Hi,

This is probably easy, but I can't work it out.

I have a macro that while running, it is necessary to select cells, due to paste special values.

How can I get excel to remember what cell or range was active at the start of the macro, and then return to the same cell or range at the end.

Thanks


Ben
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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