Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Return to current worksheet

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.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Return to current worksheet

Sub GoBackHomeDemo()
Dim sh as Worksheet, sh1 as Worksheet
set sh1 = Activesheet
for each sh in Worksheets
sh.Activate
Next
sh1.Activate
End Sub


--
Regards,
Tom Ogilvy


"Patrick Simonds" wrote:

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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Return to current worksheet

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
return the current row number for use in a formula CuriousMark Excel Discussion (Misc queries) 2 May 6th 08 02:53 AM
use the current time to return a value [email protected] Excel Discussion (Misc queries) 2 November 28th 05 05:08 PM
use the current time to return a value sd Excel Programming 4 November 28th 05 04:19 PM
Function to return the current Worksheet name? Steve Excel Worksheet Functions 6 June 29th 05 04:36 AM
Return number of current sheet Brandon Excel Worksheet Functions 3 April 26th 05 05:55 AM


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"