Rename sheet based on cell on another sheet within the same workbook

itsrich

New Member
Joined
Apr 13, 2009
Messages
49
Office Version
  1. 2019
Platform
  1. Windows
I use the same Excel file over and over. I just rename it and use it again.

Cell F5 on sheet "Work Sheet" has TXSP190SC-T in it. Sheet "(this name changes) Parts List" is currently in the Workbook. The component name for this sheet is Boat_01 (I named such in my efforts to figure this all out).

So...

I want to rename the sheet currently named "OLV165SC Parts List" to "TXSP190SC-T Parts List" using the cell contents from "Work Sheet" cell F5 = TXSP190SC-T. F5 will change every time I reuse the file.

TY for sharing your knowledge!
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Do you have a formula in F5?
Or is it a value that you change manually?
Do you want the sheet name to be changed automatically or by pressing a button?
 
Upvote 0
No formula. Changing automatically would be great! Thought to help me in my learning, can you post both auto and button so I can see the difference. I do not wish to impose though. TYVM!
 
Upvote 0
Changing automatically

Right click the tab of the sheet ("Work Sheet") you want this to work, select view code and paste the code into the window that opens up.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  If Target.CountLarge > 1 Then Exit Sub
  If Target.Address(0, 0) = "F5" Then
    If Target.Value = "" Then Exit Sub
    Dim sh As Worksheet
    Dim exists As Boolean
    Dim suf As String
    
    suf = "Parts List"
    For Each sh In Sheets
      If LCase(Right(sh.Name, 10)) = LCase(suf) Then
        sh.Name = Target.Value & " " & suf
        exists = True
        Exit For
      End If
    Next
  End If
  If exists Then
    MsgBox "Updated name"
  Else
    MsgBox "Sheet with suffix 'Parts list'", vbExclamation, "Does not exist"
  End If
End Sub

__________________________________________________________________
With a button

VBA Code:
Sub ChangeName()
  Dim sh As Worksheet
  Dim exists As Boolean
  Dim suf As String
  
  If Range("F5").Value = "" Then Exit Sub
  suf = "Parts List"
  For Each sh In Sheets
    If LCase(Right(sh.Name, 10)) = LCase(suf) Then
      sh.Name = Range("F5").Value & " " & suf
      exists = True
      Exit For
    End If
  Next
  If exists Then
    MsgBox "Updated name"
  Else
    MsgBox "Sheet with suffix 'Parts list'", vbExclamation, "Does not exist"
  End If
End Sub
 
Upvote 0
Solution
So if I read the code correctly, you look through all the sheet names until you found a match for "Parts List" and then replace it. WOW, I was looking in the wrong direction. Thank you for enlightening me! This a simple and elegant way to reach the goal!
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

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