VBA for Dynamic sheet name with auto update option based on a list of names

mistersend

New Member
Joined
May 29, 2020
Messages
15
Office Version
  1. 2019
Platform
  1. Windows
I have a list of 4 (ACTUALLY 80, but simplified) students on Sheet1. I have made 4 sheets, 1 sheet for each student. I want to rename these 4 sheets on the basis of the name in the list, so that whenever I update the name list, the corresponding sheet-name changed automatically, without going to that sheet or manually running the macro again and again. I already have the following code in the workbook to hide the sheet which are not in use:

Private Sub Worksheet_Change(ByVal Target As Range)
If [A1] = "" Then
Sheet2.Visible = False
Else
Sheet2.Visible = True
End If
If [A2] = "" Then
Sheet3.Visible = False
Else
Sheet3.Visible = True
End If
If [A3] = "" Then
Sheet4.Visible = False
Else
Sheet4.Visible = True
End If
End Sub


I have the following code which can rename the sheet but only 1 sheet, not all:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Set Target = Sheet1.Range("B2")
If Target = "" Then Exit Sub
Sheet2.Name = Left(Target, 31)
Exit Sub
End Sub


I don't know how to apply both the code simultaneously.
Please help, if anyone have any solution.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
can anyone help to combine these 3 code in one form

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Set Target = Sheet1.Range("A1")
If Target = "" Then Exit Sub
Sheet2.Name = Left(Target, 31)
Exit Sub
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Set Target = Sheet1.Range("A2")
If Target = "" Then Exit Sub
Sheet3.Name = Left(Target, 31)
Exit Sub
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Set Target = Sheet1.Range("A3")
If Target = "" Then Exit Sub
Sheet4.Name = Left(Target, 31)
Exit Sub
End Sub
 
Upvote 0
Solved!
The solution can be found here...
 
Upvote 0
For future reference.
While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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