Return to current worksheet

  • Thread starter Thread starter Patrick Simonds
  • Start date Start date
P

Patrick Simonds

I have a macro which when it runs cycle through all the worksheets in my
workbook. When it finishes it leaves me on the last worksheet of the
workbook. I would like to be returned to the worksheet that was active when
the macro was started.
 
Sub GoBackHomeDemo()
Dim sh as Worksheet, sh1 as Worksheet
set sh1 = Activesheet
for each sh in Worksheets
sh.Activate
Next
sh1.Activate
End Sub
 
Define a variable as a string to capture your macro workbook name

Dim MainWB as string

MainWB=ActiveWorkbook.Name 'place this somewhere near the beginning
of your macro

......after sub runs, near end of macro

Windows(MainWB).Activate

....for more specifics, you could also add the following
Sheets("insertSheetNameHere").Select
Range("A1").Select

---Joran6
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top