Link to home
Start Free TrialLog in
Avatar of RWayneH
RWayneHFlag 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
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

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
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RWayneH

ASKER

Thanks for the help.