0

I can successfully name my sheet tab based on a cell reference in the same sheet with the following VBA code:

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
    Set Target = Range("A1")
    If Target = "" Then Exit Sub
    On Error GoTo Badname
    ActiveSheet.Name = Left(Target, 31)
    Exit Sub
Badname:
    MsgBox "Please revise the entry in A1." & Chr(13) _
    & "It appears to contain one or more " & Chr(13) _
    & "illegal characters." & Chr(13)
    Range("A1").Activate
End Sub

However, I am struggling to change the sheet tab based on a cell reference in the title sheet. I have tried simply replacing the range with the reference from the desired sheet, Range("Keywords!A1"), but this does not seem to work.

Any suggestions to get around this would be hugely appreciated.

1 Answer 1

4

Use this to reference another worksheet

Worksheets("Keywords").Range("A1").Value
Sign up to request clarification or add additional context in comments.

1 Comment

Just to add further context, you can use Sheets as well. This explains the difference quite well. For this example though it doesn't matter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.