Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
michaelberrier
 
Posts: n/a
Default Referring to the previous selected sheet in a macro

Is there anyway to refer to the previous selected sheet in a macro?

In other words, the macro is designed on a sheet named "Master" and
switches back and forth between that sheet and another, lets call it
"Output".

"Master" is designed to be copied and renamed, but it always references
"Output" in certain macros.

The code currently begins on "Master" and goes something like this:

Range("A1:A10").Copy
Sheets("Output").Select
Range("A1:A10").Paste
Sheets("Master").Select
....and so on.

I need that same functionality if "Master" is named "Master2" or
"AbeVigoda" or whatever. Does VBA include syntax for Previous Sheet or
Last sheet or anything so that you can tell the macro to go back to
sheet it started from?

Thanks to all.

  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone
 
Posts: n/a
Default Referring to the previous selected sheet in a macro

Assuming the ActiveSheet is the start sheet then just assign the
sheet name to a string variable....
Dim strSheetName as String
strSheetName = ActiveSheet.Name
Use it like this...
WorkSheets(strSheetName).Range("xyz").Copy
-or-
Set an Object Variable to the ActiveSheet...
Dim objSheet as Excel.Worksheet
Set objSheet = ActiveSheet
Use it like this...
ObjSheet.Range("xyz").Copy
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"michaelberrier"

wrote in message
Is there anyway to refer to the previous selected sheet in a macro?
In other words, the macro is designed on a sheet named "Master" and
switches back and forth between that sheet and another, lets call it
"Output".
"Master" is designed to be copied and renamed, but it always references
"Output" in certain macros.
The code currently begins on "Master" and goes something like this:

Range("A1:A10").Copy
Sheets("Output").Select
Range("A1:A10").Paste
Sheets("Master").Select
....and so on.
I need that same functionality if "Master" is named "Master2" or
"AbeVigoda" or whatever. Does VBA include syntax for Previous Sheet or
Last sheet or anything so that you can tell the macro to go back to
sheet it started from?
Thanks to all.

  #3   Report Post  
Posted to microsoft.public.excel.misc
michaelberrier
 
Posts: n/a
Default Referring to the previous selected sheet in a macro

Absolutely PERFECT! Thanks a lot.

Jim Cone wrote:
Assuming the ActiveSheet is the start sheet then just assign the
sheet name to a string variable....
Dim strSheetName as String
strSheetName = ActiveSheet.Name
Use it like this...
WorkSheets(strSheetName).Range("xyz").Copy
-or-
Set an Object Variable to the ActiveSheet...
Dim objSheet as Excel.Worksheet
Set objSheet = ActiveSheet
Use it like this...
ObjSheet.Range("xyz").Copy
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"michaelberrier"

wrote in message
Is there anyway to refer to the previous selected sheet in a macro?
In other words, the macro is designed on a sheet named "Master" and
switches back and forth between that sheet and another, lets call it
"Output".
"Master" is designed to be copied and renamed, but it always references
"Output" in certain macros.
The code currently begins on "Master" and goes something like this:

Range("A1:A10").Copy
Sheets("Output").Select
Range("A1:A10").Paste
Sheets("Master").Select
...and so on.
I need that same functionality if "Master" is named "Master2" or
"AbeVigoda" or whatever. Does VBA include syntax for Previous Sheet or
Last sheet or anything so that you can tell the macro to go back to
sheet it started from?
Thanks to all.


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
use macro button to run macro in protected sheet earl Excel Discussion (Misc queries) 3 February 26th 06 10:21 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
2 questions, copying data from sheet to sheet and assigning macro Boris Excel Worksheet Functions 0 December 16th 04 06:11 PM
Macro, select Sheet "Number", NOT Sheet Name DAA Excel Worksheet Functions 4 November 30th 04 05:29 PM
referring to previous sheet Iolao Excel Discussion (Misc queries) 3 November 26th 04 08:40 PM


All times are GMT +1. The time now is 01:04 PM.

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

About Us

"It's about Microsoft Excel"