Rename Tabs Based on a Contents Page

G16LYB

New Member
Joined
Nov 23, 2021
Messages
14
Office Version
  1. 365
Platform
  1. Windows
Hi

Apologies I know this has been asked before but I cant find anything that seems to cover this specifically.

I have a workbook that I want to have a contents page with a reference number, I've then linked this reference to another sheet in cell A1. I've found some basic code that renames the tab, but if the reference changes in the contents it doesn't update the sheet unless you go into it and click into a cell.

I'll need a lot of tabs in the workbook, possibly 200 with the ability to add more if required.

I'm pretty proficient with excel, but I've zero experience with VBA so detailed instructions would be really helpful.

Thanks
 
The details in Contents is coming from another tab called Audit Trail
 
Upvote 0

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Ok, are the cells with the sheet names being manually change on the Audit trail tab? If not where are the being changed?
 
Upvote 0
The audit trail tab will be the source of the data.

Its Purchase Invoices if that helps with context. Each invoice will be given an internal reference, which I want to cascade through the tab names
 
Upvote 0
Ok what cells in the audit trail tab have the sheet names?
 
Upvote 0
Ok how about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim OldName As String, NewName As String

   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("F2:F500")) Is Nothing Then
      If Target.Value = "" Then Exit Sub
      Application.EnableEvents = False
      NewName = Target.Value
      Application.Undo
      OldName = Target.Value
      Target.Value = NewName
      If Not Evaluate("isref('" & OldName & "'!a1)") Then
         MsgBox "Sheet " & OldName & " does not exist"
      ElseIf Evaluate("isref('" & NewName & "'!a1)") Then
         MsgBox "Sheet " & NewName & " already exists"
      Else
         Sheets(OldName).Name = NewName
      End If
   End If
   Application.EnableEvents = True
End Sub
This needs to go in the Audit Trail tab.
 
Upvote 0
Did you put the code in the Audit Trail tab's code module & then change a single cell in f2:f500?
 
Upvote 0
In that case it should work. Did you get any error messages, or a message box?
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

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