Avatar of RWayneH
RWayneH
Flag for United States of America asked on

Getting a date as a sheet tab name using VBA?

Had a date in a cell, stored it to clipboard to use as a sheet tab name.  How come I can do this manually, but not when it is run as a macro?  Please advise and thanks

Trying:

Sheets("Historical_SelectionStocking_Ef").Select
    Range("E1").Select
    Selection.NumberFormat = "mm-dd-yy"
    NewSheetTabName = ActiveCell.Value
    Sheets("Historical_SelectionStocking_Ef").Name = NewSheetTabName
VBAMicrosoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
RWayneH

8/22/2022 - Mon
Sam Jacobs

Try this:
    Sheets("Historical_SelectionStocking_Ef").Select
    NewSheetTabName = Format(Range("E1").Value, "mm-dd-yy")
    Sheets("Historical_SelectionStocking_Ef").Name = NewSheetTabName

Open in new window

You could do it all in one line if you wish:
Sheets("Historical_SelectionStocking_Ef").Name = Format(Sheets("Historical_SelectionStocking_Ef").Range("E1").Value, "mm-dd-yy")

Open in new window

ASKER CERTIFIED SOLUTION
Rob Henson

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
RWayneH

ASKER
Thanks for the help.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23