I need, in a macro, to get the current sheet's name and save it as a variable for use later in the same macro. Later in the macro, I need to be able to tell Excel to select the sheet who's name is stored in the variable.Here's what I'm doing:My macro starts on the ActiveSheet (need to get name)I do some actions which take me to another sheet (named)I need to return to the first sheet (name now stored in variable) to clean up my mess (from my calculations).Anyone tell me how to do that? I've been playing with trying to assign a variable like this:Dim shCurr As WorksheetSet shCurr =ActiveSheetSheets(ActiveSheet).Selectbut it doesn't work (I must be doing something stupid here.it is Friday, afterall).ToddK. There are a few different ways to do this, one you can set an object reference to the sheet, or two, you can store the actual sheet name, and then use that.

See below for example.Sub GetSheetDim ActSheet As WorksheetDim ActSheetName As String'This sets up an object reference to the activesheetSet ActSheet = Sheets(ActiveSheet.Name)'This places a string value in the variableActSheetName = ActiveSheet.Name'Both of these will do the same thingActSheet.ActivateSheets(ActSheetName).ActivateSet ActSheet = NothingEnd Sub. (8 responses) I am using the below code to add fields to my pivot table. It works great, but my problem is it only works for one pivot table on each page.(8 responses) In a folder I have 2000+ files. I have to copy from each sheet1, range C5: Cx (each file has a certain number of rows.), in the 'Mast.(7 responses) I have four comboboxes with twelve colours on the list (each has an identical list). Say the colour 'Red' is selected in the combob.(17 responses) I have an excel sheet that has about 5000+ Sku's from over 150+ vendors, my excel sheet has a vendor column ( C ), I am going throught.(7 responses) I have a bank of data that is updated monthly.

Excel VBA Worksheets VBA Activesheet vs Worksheets, Select, Activate etc. (2 votes, average: 4.50 out of 5). On the right we have a screen from an example Workbook. The VBAName string is the VBA Name of our Worksheet. Although you ran a macro from Book1.xlsm, VBA considers always the top-most worksheet as the ActiveSheet. This macro sets today's date as the name for the current sheet Sub. Have questions or feedback about Office VBA or this documentation?

I need to analyze said data to determine first all values above 35 then I need to look for two.The Holy Grail of Excel Tips $12.60.

Active3 months ago

I would like to create an user-defined function in Excel that can return the current worksheet. I could use the

But the problem with this is, it works and suddenly it starts to get different sheet name. Wolfgang amadeus phoenix mega. For example, instead of SHEET I LOVE YOU it returns SHEET I HATE YOU.

Is there anyway to fix this - or it might possible because I think it can not be static but varies?

Community
user2103670user2103670
60810 gold badges16 silver badges24 bronze badges

5 Answers

mucioMacromucio
6,3081 gold badge15 silver badges29 bronze badges
josefjosef
mobermemoberme

You can use below code to get the Active Sheet name and change it to yours preferred name.

Rohit PalRohit Pal

Extend Code for Show Selected Sheet(s) [ one or more sheets].

Excel
ChaCha CJ RuneChaCha CJ Rune

Not the answer you're looking for? Browse other questions tagged excelexcel-vbavba or ask your own question.