Full Version: Sheet Name
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
calindoo
Have a file with several protected sheets, with a cell which reflects the sheet name.

Is it possible to have the sheet name update automatically when changed?


Thanks

CD
StuKiel
Hi CD,

Not sure which way round you meant.

This formula will return the sheet name.

=RIGHT(CELL("filename"),LEN(CELL("filename"))-FIND("]",CELL("filename")))

Below this code will change the sheet name of Worksheets "Sheet1" and "Sheet2", to reflect whatever is typed into cell E2.
CODE
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim strPwd As String
Dim rngSheetName As Range

strPwd = "yourpassword"
Set rngSheetName = Range("E2")

Select Case Sh.Name
    Case Is = "Sheet1", "Sheet2"
        If Not (Intersect(Target, rngSheetName) Is Nothing) Then
            With Sh
                .Unprotect Password:=strPwd
                .Name = Target.Value
                .Protect Password:=strPwd, DrawingObjects:=True, Contents:=True, Scenarios:=True
            End With
        End If
    Case Else
End Select
End Sub


HTH
Stu
calindoo
Stu

Many thanks for the reply.

The formual works but returns seems to display the same value in different sheets?

CD
StuKiel
Hi CD,

Ah, ok. Try this instead:

=RIGHT(CELL("filename",A1),LEN(CELL("filename",A1))-FIND("]",CELL("filename",A1)))

HTH
Stu.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.