VBA code - Rename a tab/sheet automatically when updating A1 that contains a formula

NTschanun

New Member
Joined
Jul 30, 2010
Messages
13
Hi,
i am working on office 2007 with Windows XP.

i have the following code already available:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
'one cell at a time
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Sh.Range("A1")) Is Nothing Then
Exit Sub 'not in A1
End If
On Error Resume Next 'just in case it's not a valid name
Sh.Name = Sh.Range("a1").Value
If Err.Number <> 0 Then
MsgBox Sh.Name & " cannot be renamed to: " & Target.Value
Err.Clear
End If
On Error GoTo 0
End Sub

However this code does not enable me to update the sheetname when the cell A1 is a formula and when the formula in A1 is updated.

I would like to have the sheet name updated as soon as the formula in AD1 is updated.

Hope someone can help.
Regards,
Nicolas
 
VoG,
thanks it works. I pasted the code under the workbook code and not under the sheet code.
But when i enable the marco the worksheet and workbook bugs.
Can this be due to the fact that the xls file is save under Microsoft Office Excel 97-2003 Worksheet instead of Microsoft Office Excel 2007 Worksheet ?

Nicolas
 
Upvote 0

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
What error do you get? If you click Debug which line of code is highlighted?
 
Upvote 0
VoG,
It works now, i pasted the code under the workbook code and not under the sheet code.
However when runing the enabling the macro.. once the sheet names are updated, the workbook bugs. is it because i have links to a sharepoint ? or can this be due to the fact that the work book is saved under an older version of excel then excel 2010 ?
 
Upvote 0
What do you mean by "bugs"?

I'm afraid I don't know anything about Sharepoint.

It shouldn't matter that it is saved in XL 97-2003 format.
 
Upvote 0
bobsan42,
the formula in cell A1 is a link to a different sheet in the same workbook (=+'Fcst Scope'!$T$8).
in the other sheet the formula is refering to another formula index,match,match on the same sheet that extract data from another excel file stored on a sharepoint using the formula index,match,match.
hope this helps
 
Upvote 0
bobsan42,
the formula in cell A1 is a link to a different sheet in the same workbook (=+'Fcst Scope'!$T$8).
in the other sheet the formula is refering to another formula index,match,match on the same sheet that extract data from another excel file stored on a sharepoint using the formula index,match,match.
hope this helps
:eek: wowwww :oops:
then better stick to the Calculate event procedure by VoG
 
Upvote 0
VoG,
Can i use the same code as shared:

Private Sub Worksheet_Calculate()
On Error Resume Next
Me.Name = Range("AD1").Value
On Error GoTo 0
End Sub

in the same workbook but on 3 different sheets ?

If i have the code only on one sheet in the workbook, excel continues to work properly.
If i copy paste the same code in 2 or 3 sheets in the same workbook excel stop responding.

Do we need to amend something to the code ?

Thanks for your input.
Nicolas
 
Upvote 0
VoG,
Can i use the same code as shared:

Private Sub Worksheet_Calculate()
On Error Resume Next
Me.Name = Range("AD1").Value
On Error GoTo 0
End Sub

in the same workbook but on 3 different sheets ?

If i have the code only on one sheet in the workbook, excel continues to work properly.
If i copy paste the same code in 2 or 3 sheets in the same workbook excel stop responding.

Do we need to amend something to the code ?

Thanks for your input.
Nicolas
<!-- / message -->
 
Upvote 0

Forum statistics

Threads
1,215,632
Messages
6,125,909
Members
449,274
Latest member
mrcsbenson

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