ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   vb code for renaming a work sheet with a cell reference (https://www.excelbanter.com/excel-discussion-misc-queries/110324-vbulletin-code-renaming-work-sheet-cell-reference.html)

John Britto

vb code for renaming a work sheet with a cell reference
 
I would like to change the sheet name automatically whenever a cell reference
is changed

Bob Phillips

vb code for renaming a work sheet with a cell reference
 
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Name = .Name
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"John Britto" wrote in message
...
I would like to change the sheet name automatically whenever a cell

reference
is changed




Don Guillett

vb code for renaming a work sheet with a cell reference
 
What you need is a worksheet_change event. Right click the sheet tabview
codeleft window select worksheetright window select changeput in your
macro

if target.address="$A$1" then activesheet.name=target

--
Don Guillett
SalesAid Software

"John Britto" wrote in message
...
I would like to change the sheet name automatically whenever a cell
reference
is changed




Tom Ogilvy

vb code for renaming a work sheet with a cell reference
 
think Bob meant

Me.Name = .Name
should be
Me.Name = .Value


--
Regards,
Tom Ogilvy


"Bob Phillips" wrote in message
...
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H10" '<=== change to suit

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Me.Name = .Name
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"John Britto" wrote in message
...
I would like to change the sheet name automatically whenever a cell

reference
is changed







All times are GMT +1. The time now is 11:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com