Macro to change tab name to date from a cell ref

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey all

Here we go. The workbook contains sheets for each business day of the month. Each day a new sheet is added. The user renames the added sheet to "New" and clicks an Update button to compile the data onto a summary worksheet. I would like the macro to also rename the added sheet to the date that appear in cell E2 in this format: yyyymmdd. I have tried to format the date in the cell, but the macro gives me the error CANNOT USE [ or / . Although the date appears as yyyymmdd, in the formula bar it is still mm/dd/yyyy

Any help is greatly appreciated.
 
Hi
try something like
Dim wks_new as worksheet
....
set wks_new = worksheets("new name")
wks_new.name = Format(wks_new.range("E2").value, "yyyymmdd")

--
Regards
Frank Kabel
Frankfurt, Germany
cwilson said:
Hey all,

Here we go. The workbook contains sheets for each business day of
the month. Each day a new sheet is added. The user renames the added
sheet to "New" and clicks an Update button to compile the data onto a
summary worksheet. I would like the macro to also rename the added
sheet to the date that appear in cell E2 in this format: yyyymmdd. I
have tried to format the date in the cell, but the macro gives me the
error CANNOT USE [ or / . Although the date appears as yyyymmdd, in
the formula bar it is still mm/dd/yyyy.
 
One way:

With Worksheets("NEW")
.Name = Format(.Range("E2").Value, "yyyymmdd")
End With
 
With Worksheets("New")
.Name = format(.Range("E2").Value,"yyyymmdd")
End With

--
Regards,
Tom Ogilvy

cwilson said:
Hey all,

Here we go. The workbook contains sheets for each business day of the
month. Each day a new sheet is added. The user renames the added sheet to
"New" and clicks an Update button to compile the data onto a summary
worksheet. I would like the macro to also rename the added sheet to the
date that appear in cell E2 in this format: yyyymmdd. I have tried to
format the date in the cell, but the macro gives me the error CANNOT USE [
or / . Although the date appears as yyyymmdd, in the formula bar it is
still mm/dd/yyyy.
 
Try this

With Worksheets("New")
..Name = Format(.Range("E2"), "yyyymmdd")
End With

Or

With Worksheets("New")
..Name = Format(.Range("E2"), "yyyy-mm-dd")
End With




--
Regards Ron de Bruin
(Win XP Pro SP-1 XL2000-2003)




cwilson said:
Hey all,

Here we go. The workbook contains sheets for each business day of the month. Each day a new sheet is added. The user
renames the added sheet to "New" and clicks an Update button to compile the data onto a summary worksheet. I would like the
macro to also rename the added sheet to the date that appear in cell E2 in this format: yyyymmdd. I have tried to format the
date in the cell, but the macro gives me the error CANNOT USE [ or / . Although the date appears as yyyymmdd, in the formula
bar it is still mm/dd/yyyy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top