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: 36
  • Picture 2.png
    Picture 2.png
    14 KB · Views: 40

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
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

Forum statistics

Threads
1,224,815
Messages
6,181,135
Members
453,021
Latest member
Justyna P

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