How do I rename a sheet without knowing in advance what it's called?

bigpat

New Member
Joined
Nov 28, 2012
Messages
24
I know how to rename a sheet when I already know what the sheet name is going to be. For example I geta weekly file from an external source and I rename it as follows.


Code:
'Rename sheet in Study Summary
    Workbooks.Open Filename:= _
        "G:\Database\Database files\Study Summary.xlsx"
    Sheets("Study SummaryDATA").Select
    Sheets("Study SummaryDATA").Name = "Study Summary"
    Range("A1").Select
    ActiveWorkbook.Save
    ActiveWindow.Close
But now I'm also exporting data from another system. I save it as "My data" each time, overwriting the previous copy, but the sheet name is a long string of characters such as "4d604f91760a4a3c80d416ad6a192f5" which changes each time.


So how do I say something like this?


Sheets("whatever_its_called").Select
Sheets("whatever_its_called").Name = "Sheet1"
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,135
Office Version
365
Platform
Windows
If there is only one sheet in the file, just use:
Code:
ActiveSheet.Name = "Sheet1"
Or, if it is always the first sheet in the file, you can use:
Code:
Sheets(1).Name = "Sheet1"
Otherwise, you need some logic to determine which sheet it is that needs to be renamed.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
54,135
Office Version
365
Platform
Windows
You are welcome.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,306
Messages
5,510,507
Members
408,792
Latest member
S_s_s

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top