View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
fujing1003 fujing1003 is offline
external usenet poster
 
Posts: 11
Default Update sheetname from cell, automatically

On Jan 2, 5:12 am, wrote:
Can this be modified so a cell that is changed on another worksheet be
the trigger instead of the cell of the current worksheet. for example
cell "A3" on a worksheet named "Setup"? Thanks to anyone that can
help.

Sheetname from cell, automatically

If you want to have your sheet name change when a cell value is
changed, you can use this Worksheet_Change() event macro. Put it in
your worksheet code module. Note that it has minimal error checking.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Const sNAMECELL As String = "A1"
Const sERROR As String = "Invalid worksheet name in cell "
Dim sSheetName As String

With Target
If Not Intersect(.Cells, Range(sNAMECELL)) Is Nothing Then
sSheetName = Range(sNAMECELL).Value
If Not sSheetName = "" Then
On Error Resume Next
Me.Name = sSheetName
On Error GoTo 0
If Not sSheetName = Me.Name Then _
MsgBox sERROR & sNAMECELL
End If
End If
End With
End Sub

Change the value of sNAMECELL to your desired cell.

This page last updated Sunday, 28 November 2004


Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
Range)
Const sNAMECELL As String = "A3"
Const sERROR As String = "Invalid worksheet name in cell "
Dim sSheetName As String

If StrComp(Sh.Name, "Setup") < 0 Then Exit Sub
With Target
If Not Intersect(.Cells, Range(sNAMECELL)) Is Nothing Then
sSheetName = Range(sNAMECELL).Value
If Not sSheetName = "" Then
On Error Resume Next
ActiveSheet.Name = sSheetName
On Error GoTo 0
If Not sSheetName = ActiveSheet.Name Then _
MsgBox sERROR & sNAMECELL
End If
End If
End With
End Sub