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"
 

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).
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.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top