Renaming sheet with VBA

G

Guest

I am doing some checks for specific text within the existing sheet name and
if the sheet name contains that value, I want to rename it to include
information from named range abc.

I'm using this to rename the sheet

Worksheets(i).Name = "TRY IT " & Range("abc") & " - Cover
Page"

I know I've got the right worksheet, but it's not being renamed. Does the
formula need to be changed?

Thanks,
Barb Reinhardt
 
C

Chip Pearson

Barb,

Where is the code located? It should be in a regular code module,
not in a sheet module or the ThisWorkbook module. If you have it
in a sheet object module, you need to qualify the Range statement
to point to the sheet on which the range "abc" is defined. E.g,.

Worksheets(i).Name = _
"TRY IT " & Worksheets(1).Range("abc") & " - Cover Page """


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



in message
news:[email protected]...
 
E

Excelenator

I used this code to rename all the sheets in an active workbook. I had
to set up the named range on EACH sheet and use a different value in
each so that the name would not be duplicated.


Code:
--------------------
Sub RenameSht()

For i = 1 To Worksheets.Count
Worksheets(i).Activate
Worksheets(i).Name = "TRY IT " & ActiveSheet.Range("abc") & " - Cover Page"
Next

End Sub
--------------------





Barb said:
I am doing some checks for specific text within the existing sheet name
and
if the sheet name contains that value, I want to rename it to include
information from named range abc.

I'm using this to rename the sheet

Worksheets(i).Name = "TRY IT " & Range("abc") & " - Cover
Page"

I know I've got the right worksheet, but it's not being renamed. Does
the
formula need to be changed?

Thanks,
Barb Reinhardt
 

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