[英]How to rename a worksheet based on a cell value
How can I rename a sheet using based on cell A1 value from sheet 2.如何根据工作表 2 中的单元格 A1 值重命名工作表。
I tried the following code:我尝试了以下代码:
Private Sub CommandButton1_Click()
Sheet1.Name = Sheet2.Range("A1").Value
End Sub
but if I use但如果我使用
Sheets(1).Name = Sheets(2).Range("A1").Value
or或者
Sheets("Sheet1") = Sheets("Sheet2").Range("A1").Value
it works but I need to use code name of the sheets so when I rename sheet 2 the code would still work.它有效,但我需要使用工作表的代码名称,因此当我重命名工作表 2 时,代码仍然有效。
In general I found your question very unclear, but here are the 3 possible interpretations:总的来说,我发现你的问题很不清楚,但这里有 3 种可能的解释:
Set first Sheet
as the [A1]
of the 2nd Sheet
.组第一
Sheet
为[A1]
的第二的Sheet
。
Private Sub CommandButton1_Click() If Not IsEmpty(Sheets(2).Range("A1")) ThisWorkbook.Sheets(1).Name = ThisWorkbook.Sheets(2).Range("A1") End If End Sub
Set first Sheet
as the [A1]
of the last Sheet
将第一个
Sheet
设置为最后一个Sheet
的[A1]
Private Sub CommandButton1_Click() If Not IsEmpty(Sheets(Sheets.Count).Range("A1")) ThisWorkbook.Sheets(1).Name = ThisWorkbook.Sheets(Sheets.Count).Range("A1") End If End Sub
Set first Sheet
as the [A1]
of the Sheet named "Sheet2"
将第一个
Sheet
设置为名为"Sheet2"
的 Sheet 的[A1]
Private Sub CommandButton1_Click() If Not IsEmpty(Sheets("Sheet2").Range("A1")) ThisWorkbook.Sheets(1).Name = ThisWorkbook.Sheets("Sheet2").Range("A1") End If End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.