VBA Tab Name Change

SteveWr

New Member
Joined
Jan 12, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a small macro for changing the tab name of a separate worksheet when the value is changed in a specific cell on another sheet called Summary. It works okay but I cant see how to get the tab name to change automatically when the value of the cell C7 changes on the Summary sheet.

Sheet 2 does change when I click on any cell on that page. Can someone please advise?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Sheet2 As Worksheet
Set Sheet2 = ActiveWorkbook.ActiveSheet
Sheet2.Name = "" & Worksheets("Summary").Range("C7").Value
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
this in the sheetmodule of Summary is enough, i suppose.
It's converted to a string, in case you want to name the sheet with a number and sheets(2)<>sheets("2")
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Address = "$C$7" Then ThisWorkbook.Sheet2.Name = CStr(Target.Value)
End Sub
 
Upvote 0
this in the sheetmodule of Summary is enough, i suppose.
It's converted to a string, in case you want to name the sheet with a number and sheets(2)<>sheets("2")
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
     If Target.Address = "$C$7" Then ThisWorkbook.Sheet2.Name = CStr(Target.Value)
End Sub
Thank you for your reply however I get an error - Compile error: Method or data member not found when I execute this
 
Upvote 0
try it without "ThisWorkbook."
VBA Code:
Sheet2.Name = CStr(Target.Value)
 
Upvote 0
Solution

Forum statistics

Threads
1,214,971
Messages
6,122,525
Members
449,088
Latest member
RandomExceller01

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