Renaming a Worksheet using a Macro


C

chris smith

Is it possible to rename a Worksheet using a macro? I am running a
macro to move a data sheet to the far right. I would then like to run a
second macro to rename the sheet by copying and pasting a cell value
from within the sheet. i.e. the sheet has the word October in it. I
would like to change the sheet currently marked as "Current Month (2)"
to "October". Any help would be appreciated. Thanks.
Chris
 
Ad

Advertisements

J

JE McGimpsey

chris smith said:
Is it possible to rename a Worksheet using a macro? I am running a
macro to move a data sheet to the far right. I would then like to run a
second macro to rename the sheet by copying and pasting a cell value
from within the sheet. i.e. the sheet has the word October in it. I
would like to change the sheet currently marked as "Current Month (2)"
to "October". Any help would be appreciated. Thanks.
Chris
One way:

Public Sub RenameLastWorksheet()
On Error Resume Next 'in case rename fails
With Worksheets(Worksheets.Count)
.Name = .Range("A1").Text
End With
On Error GoTo 0
End Sub

The On Error Resume Next is in case the value in A1 has the same name as
an existing sheet, or perhaps has illegal characters, or is too long.

Substitute "A1" with your desired cell reference.
 
Ad

Advertisements

C

chris smith

Hi. Thanks for that. I have given it a try and am having a few compling
errors, but I will work them out but it does make sense to me. Thank
you very much for your help.
Chris
 

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

Similar Threads


Top