Worksheet Rename VBA - Referencing Cell on Another Sheet (Same Workbook)

hamiltonhere

New Member
Joined
Aug 24, 2023
Messages
2
Office Version
  1. 365
Hello,
I have the following code that only works if I am referring to a cell on the same worksheet that the code is being used on. I would like Range("A1") to actually be Cell B10 on a worksheet which is called "Master". How would I alter this code to accomplish this? Thanks in advance!

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("A1")) Is Nothing Then
If Range("A1") = Empty Then
ActiveSheet.name = "Client Unspecified-" & ActiveSheet.Index
Else
ActiveSheet.name = Range("A1")
End If
End If
End Sub
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
To trigger the change of cell B10 in the "Master" sheet (through manual change), the active sheet must be the "Master" sheet.
Assuming the sheet you want to rename is Sheet1 (based on the sheet index).This code is placed in the module of the "Master" sheet:

VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B10")) Is Nothing Then Exit Sub
With Sheet1
    If IsEmpty(Target) Then
        .Name = "Client Unspecified-" & ActiveSheet.Index
    Else
        On Error Resume Next
        .Name = Target
        If Err.Number <> 0 Then
            MsgBox "Invalid sheetname! Try again"
        End If
        On Error GoTo 0
    End If
End With
End Sub
 
Upvote 0
Thank you! That worked! I am now trying to figure out how to continue that same pattern, where Sheet2 will get renamed to the value that is in Cell D10, Sheet3 will be renamed to the value in Cell F10, Sheet4 will be renamed to the value in Cell H10, etc. I have 30 sheets that would follow this pattern. Any idea how to accomplish this?
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,234
Members
449,092
Latest member
SCleaveland

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