Copy Sheet and Rename All Named Ranges

Hello Experts,

I'm using Excel 2010 and I'd like to accomplish the following using vba code:

1.

Copy the last worksheet in workbook

2.

Prompt user to enter a name for the newly copied worksheet and rename the worksheet with the User's input

3.

Rename part of all existing named ranges in the newly copied worksheet.  For example, using the string that the user entered in Step 2, is it possible to use the vba InStr function to replace Name1 with Joe as presented in the attached spreadsheet
Please refer to attachment for example

Any help will be greatly appreciated.

Thanks,

Sura
Named-Ranges_Example.xlsx
SuraDalbinAccountantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Try this...

    Dim newSheetName As String, originalSheetName As String, nm As Name
    newSheetName = InputBox("Enter name of new sheet")
    If newSheetName = "" Then Exit Sub
    originalSheetName = Sheets(Sheets.Count).Name
    Sheets(originalSheetName).Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = newSheetName
    For Each nm In ActiveSheet.Names
       nm.Name = Replace(Replace(nm.Name, originalSheetName, newSheetName), newSheetName & "!", "")
    Next

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SuraDalbinAccountantAuthor Commented:
This works perfectly.  Thank you very much!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.