Rename multiple sheets based on sheets number and cell value

priisha

New Member
Joined
Apr 4, 2022
Messages
22
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

I'm trying to create a macro for my excel file where I want it to rename sheets name based on a certain range in one sheets and each cell value will refer to a specific sheet number

Attached an example excel file

I want to use the value in the sheet ProjectInfo range between B20:B29
The sheet I want to rename are the one yellow marked and starts with Prx.
Note! The sheets are created no in order which mean that one PRx file might be sheet2 and another one might be sheet 4

I've looked around and found this thread to change multiple sheet from range however it changes all sheets in the workbook and it does not work with my purpose

please help me
 

Attachments

  • Picture 1.png
    Picture 1.png
    26.5 KB · Views: 17
  • Picture 2.png
    Picture 2.png
    14 KB · Views: 16

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Hi priisha,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim clnNewSheetNames As New Collection
    Dim rngCell As Range
    Dim ws As Worksheet
    Dim i As Long
    
    Application.ScreenUpdating = False

    For Each rngCell In Sheets("ProjectInfo").Range("B20:B24")
        clnNewSheetNames.Add CStr(rngCell)
    Next rngCell
    
    For Each ws In ThisWorkbook.Sheets
        If StrConv(Left(ws.Name, 3), vbUpperCase) = "PRX" Then
            i = i + 1
            ws.Name = CStr(clnNewSheetNames(i))
        End If
    Next ws
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 1
Solution
thanks for your help, I figured another vba code that worked but learned something new with your code
 
Upvote 0
thanks for your help, I figured another vba code that worked but learned something new with your code

Glad to have helped 👍
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top