• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Rename Worksheets Based on Two Named Ranges

bkanne

Member
Hi there, I've attached a sample workbook which should clearly illustrate the problem I am trying to solve.

I'd like to be able to rename the individual worksheets in a workbook based on two lists (shown in the same file). I've named both of these ranges.

Can someone please help me write a macro that will rename all the sheets in the workbook that are listed in the range (but also leave the names not mentioned in the range untouched)?

Please let me know of any questions and thanks so much as always!
 

Attachments

  • Worksheet_Renaming_Template_v01.xlsx
    41.7 KB · Views: 5
try this in your file

Code:
Sub SheetRenamer()

Dim Rng As Range
Dim SubRng As Range
Dim LstRow As Integer

With Worksheets("HOME")
    LstRow = .Cells(.Rows.Count, "C").End(xlUp).Row
    Set Rng = .Range("$C$11:$C$" & LstRow)
End With

For Each SubRng In Rng
    ActiveWorkbook.Worksheets(SubRng.Text).Name = SubRng.Offset(0, 2)
Next SubRng


End Sub
 
Something like below?
Code:
Sub Demo()
Dim i as Long
With Range("CURRENT_Names")
    On Error Resume Next
    For i = 1 To .Rows.Count
        Worksheets(.Cells(i, 1).Value).Name = Range("Desired_Names").Cells(i, 1).Value
    Next
End With

End Sub
 
Back
Top