VBA: Using Macro to set sheet name from cell, but this won't work if cell is formula, can you help me?

Jeester

New Member
Joined
Sep 6, 2014
Messages
17
Basically, I am using:

Code:
[COLOR=#000000][FONT=Courier New]Private Sub Worksheet_Change(ByVal Target As Range)ActiveSheet.Name = Range("C2").ValueEnd Sub[/FONT][/COLOR]


To name my worksheet where:

Code:
C2='List of Students'!D5

In this instance the worksheet does not update this name when I update D5 in the other worksheet as C2 is a formula. Does anyone know of a fix for this?

Cheers

Jeester
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Change it to a worksheet _activate event.
When you then activate the sheet it will update the sheet name
 
Upvote 0
Thank you!
It works great! (Though only when I click on the sheet, if you know a way where it can change without having to open the worksheet whos name is changing that would be fantastic, but this is great really!)

I'm still pretty new at VBA (ie I started using it yesterday!).
 
Upvote 0
Another option would be to put this code in the "This Workbook" module
It will trigger when ANY worksheet is recalculated.
Change the number in red to whatever the Sheets code name is
The code name of the sheet is the one OUTSIDE the brackets, when you look at it in the VBE project Explorer
Rich (BB code):
Private Sub Workbook_sheetcalculate(ByVal sh As Object)
Sheet1.Name = Sheet1.Range("C2").Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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