ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Renaming Tabs in a Macro (https://www.excelbanter.com/excel-discussion-misc-queries/208374-renaming-tabs-macro.html)

Liz C

Renaming Tabs in a Macro
 
Hi! I have an existing macro that reformats several things on a workheet and
then copies the worksheet to another worksheet in the same book and sorts it
in a different order. I then have to manually rename the two worksheets -
the first one to "20081030 by Name" and the second tab to "20081030 by Loc",
where 20081030 is the date.

What would I add in the macro to change the two tabs automatically to the
current date and "by Name" and the current date and "by Loc"?

Thanks in advance for your help!

Liz

Sheeloo[_3_]

Renaming Tabs in a Macro
 
Worksheets("Old Name").Name = "New Name"

"Liz C" wrote:

Hi! I have an existing macro that reformats several things on a workheet and
then copies the worksheet to another worksheet in the same book and sorts it
in a different order. I then have to manually rename the two worksheets -
the first one to "20081030 by Name" and the second tab to "20081030 by Loc",
where 20081030 is the date.

What would I add in the macro to change the two tabs automatically to the
current date and "by Name" and the current date and "by Loc"?

Thanks in advance for your help!

Liz


Liz C

Renaming Tabs in a Macro
 
That'll work, but how do I get it to put the current date in the correct
format as part of the name?

"Sheeloo" wrote:

Worksheets("Old Name").Name = "New Name"

"Liz C" wrote:

Hi! I have an existing macro that reformats several things on a workheet and
then copies the worksheet to another worksheet in the same book and sorts it
in a different order. I then have to manually rename the two worksheets -
the first one to "20081030 by Name" and the second tab to "20081030 by Loc",
where 20081030 is the date.

What would I add in the macro to change the two tabs automatically to the
current date and "by Name" and the current date and "by Loc"?

Thanks in advance for your help!

Liz


Sheeloo[_3_]

Renaming Tabs in a Macro
 
Sample code to get the date in the desired format
Sub t()
Dim effdate As Long
effdate = Right(Date, 4) & Left(Date, 2) & Mid(Date, 4, 2)
MsgBox effdate
End Sub

My default date format is mm/dd/yyyy
You may have to re-arrange the components if your format is different
MsgBox date will tell you what you have

"Liz C" wrote:

That'll work, but how do I get it to put the current date in the correct
format as part of the name?

"Sheeloo" wrote:

Worksheets("Old Name").Name = "New Name"

"Liz C" wrote:

Hi! I have an existing macro that reformats several things on a workheet and
then copies the worksheet to another worksheet in the same book and sorts it
in a different order. I then have to manually rename the two worksheets -
the first one to "20081030 by Name" and the second tab to "20081030 by Loc",
where 20081030 is the date.

What would I add in the macro to change the two tabs automatically to the
current date and "by Name" and the current date and "by Loc"?

Thanks in advance for your help!

Liz



All times are GMT +1. The time now is 07:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com