How to return to worksheet where macro started?

  • Thread starter Thread starter Bob Arnett
  • Start date Start date
B

Bob Arnett

I have a macro that turns off screen updating and then proceeds to jump
around to different worksheets to copy/paste/change some cells. At the end of
this macro process, before I turn screen updating back on, I want to return
to the cell/worksheet that I was on when I started started the macro running.
This is not always the same cell/worksheet and I can't seem to find how one
would do this. Any suggestions?
 
Hello

If I inderstande your question :

Before the traitement you declare an objet range

MyRange = activesheet.select

And, after the traitement you reposituonne the selection
MyRange.parent.parent.activate
MyRange.parent.select
MyRange.select

or, something almost

J a c q u e s
 
My suggestion is to not jump all around in the first place. It is almost
never required to select worksheets and cells to affect changes to them via
VBA. However, you did not post your code so it is a little hard for any of
us to show you how to avoid it in your particular situation.

Rick
 
Hi Bob,

As already indicated by Rick, it is rarely
necessary, or efficient to select objects;
normally it is preferable to manipulate
relevant object variables.

That said, one approach might be:

'=========>>
Public Sub Tester()
Dim rngOriginal As Range
Dim rCellOriginal As Range

Set rngOriginal = Selection
Set rCellOriginal = ActiveCell

' Your code

Application.Goto rngOriginal
rCellOriginal.Activate
End Sub
'<<=========
 
Back
Top