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

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
53,650
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
53,650
Office Version
365
Platform
Windows
You are welcome.
 

Watch MrExcel Video

Forum statistics

Threads
1,102,360
Messages
5,486,387
Members
407,544
Latest member
mguevara

This Week's Hot Topics

Top