本文介绍了VBA根据单元格值重命名工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要一个重命名我的sheetXXX的VBA代码,其中XXX是"Sheet1"表中单元格B5中的值.该宏应适用于B5中的任何值.
I want a VBA code that rename my sheetXXX, where XXX is the value in the cell B5 in "Sheet1" sheet. The macro should work for any value in B5.
我尝试了以下代码:
Sub tabname()
Dim sheetXXX As Worksheet
XXX.Name = Worksheets("Sheet1").Range("B5").Value
End Sub
推荐答案
您必须将object =设置为要重命名的实际工作表.
You have to set the object = to the actual worksheet to be renamed.
Sub tabname()
Dim sheetXXX As Worksheet
Set sheetXXX = ActiveWorkbook.Sheets("sheetXXX")
sheetXXX.Name = "Sheet" & Worksheets("Sheet1").Range("B5").Value
End Sub
如果将sheetXXX用作活动工作表,则应执行此操作.
If sheetXXX is meant to be the active worksheet you would do this.
Sub tabname()
Dim sheetXXX As Worksheet
Set sheetXXX = ActiveWorkbook.Activesheet
sheetXXX.Name = "Sheet" & Worksheets("Sheet1").Range("B5").Value
End Sub
这篇关于VBA根据单元格值重命名工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!