Naming sheet from cell in a different sheet

Corryn99

New Member
Joined
Sep 2, 2022
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi,

I'm creating a template to keep track of student progress, and I want to create a macro to automatically name each sheet based on values input into an overview sheet.

I started with code I found from ExtendOffice: How to name sheets based on cell values, and updated the code to this


VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set Target = Worksheets("Overview").Range("A5")
    If Target = "" Then Exit Sub
Application.ActiveSheet.Name = VBA.Left(Target, 31)
Exit Sub
End Sub

I'm not sure why but I cannot get this code to work. If I take out the Worksheets("Overview"), and assign the range to a cell within the sheet I'm trying to name, it works fine.

Any help would be appreciated!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Welcome to the Board!

If event procedures, like Worksheet_Selection, you typically do NOT set the "Target" range - it is automatic. It is the cell that was selected that triggered the code to run automatically.
Note that the way you have written it, it would call this to run anytime any cell is selected on your sheet. I don't think that is what you intended.
It also has other issues with it.

Let's take a step back. Can you tell us exactly how you want this to work?
At what point should it rename the sheet?
And obviously, I don't think every sheet will be looking at the same cell (A5), or else it would try to give them all the same name (and fail).

Please explain to us, in plain English, exactly how you envision this working.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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