Naming a worksheet tab from a reference cell

F

Finance Guru

Hi All,

Using Excel 2007

Can I name a worksheet tab from a cell contained within the worksheet. I
want to name a worksheet from the date contained in say A1 =
30/06/2009(dd/mm/yyyy)
so the tab would be called 'June' from the moonth number in A1.

If so could someone give me either the function or the code to do this. If
it is code could also detail how to apply it,as I am not that familiar with
code.

Many thanks for taking the time out to respond.

FinanceGuru
 
L

Luke M

You will need to get a formula to extract the month from your date. Sheet
names can not be blank or contain certain symbols: / \ [ ] * ?. So, in A2,
place this formula:
=TEXT(A1,"mmmm")

You'll then need to use code. This will set your sheet name to the value of
A1 when sheet is activated. Right click on the sheet tab, view code, paste
this in:

Private Sub Worksheet_Activate()
Activesheet.Name = Range("A2").Value
End Sub
 
L

Luke M

Improved code:
Rather than use a formula in worksheet, can do it directly via code with this:

Private Sub Worksheet_Activate()
ActiveSheet.Name = WorksheetFunction.Text(Range("A1").Value, "mmmm")
End Sub
 

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

Top