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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Joe4

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

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,856
Messages
5,507,735
Members
408,647
Latest member
Nicho la zido

This Week's Hot Topics

Top