Current Worksheet in a Macro

  • Thread starter Thread starter taylor2k3
  • Start date Start date
T

taylor2k3

I have a macro that sorts a number of worksheets in turn, but i want to be
able to return to the orginal worksheet i was working on. example:

I working on worksheet 2 and i run my macro to sort all worksheets, but it
sends me to the last worksheet and therefore i have to select the worksheet
tab at the bottom to get back to the worksheet i was working on. I want it
to send me back to the current worksheet automatically.

thanks
 
Hi Taylor2k3,
I working on worksheet 2 and i run my macro to sort all worksheets, but it
sends me to the last worksheet and therefore i have to select the worksheet
tab at the bottom to get back to the worksheet i was working on. I want it
to send me back to the current worksheet automatically.

At the top of your macro:

Dim oCurSht as Worksheet
Set oCurSht=Activesheet

Then at the end:

oCurSht.Activate
Set oCurSht=Nothing

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com
 
Hi
try something like the following
sub foo()
dim old_wks as worksheet
set old_wks = activesheet
' your code, processing different sheets
old_wks.activate
end sub
 
Thanks a million

Frank Kabel said:
Hi
try something like the following
sub foo()
dim old_wks as worksheet
set old_wks = activesheet
' your code, processing different sheets
old_wks.activate
end sub
 
Back
Top