[英]Excel: Name sheet tab from cell value in another sheet
I can successfully name my sheet tab based on a cell reference in the same sheet with the following VBA code: 我可以使用以下VBA代码基于同一工作表中的单元格引用成功命名工作表标签:
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. 我尝试用所需的工作表
Range("Keywords!A1")
的引用简单地替换范围,但这似乎不起作用。
Any suggestions to get around this would be hugely appreciated. 任何解决此问题的建议将不胜感激。
使用它来引用另一个工作表
Worksheets("Keywords").Range("A1").Value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.