跳到主要内容

如何基于Excel中的单元格值重命名工作表?

重命名工作表通常在我们的Excel工作中应用,但是您是否曾经尝试过根据单元格值重命名工作表? 当然,您可以手动重命名工作表,但是在本教程中,我们将介绍一些技巧,这些技巧可以根据单元格值快速重命名多个工作表,从而节省您的工作时间。

使用VBA根据特定单元重命名工作表

使用重命名多个工作表来基于特定单元格重命名工作表 好主意3

使用重命名多个工作表根据一系列单元格内容重命名工作表 好主意3


使用下面的VBA,您可以基于特定单元格重命名相对工作表。

1.选择要基于其重命名工作表的单元格,在这种情况下,选择单元格A1。 看截图:

doc重命名工作表1

2。 按 Alt + F11键 打开钥匙 Microsoft Visual Basic应用程序 窗口。

3。 点击 插页 > 模块,然后将以下VBA代码粘贴到新 模块 窗口。

VBA:根据特定的单元格值重命名工作表。

Sub RenameSheet()
'UpdatebyKutools20191129
Dim xWs As Worksheet
Dim xRngAddress As String
Dim xName As String
Dim xSSh As Worksheet
Dim xInt As Integer
xRngAddress = Application.ActiveCell.Address
On Error Resume Next
Application.ScreenUpdating = False
For Each xWs In Application.ActiveWorkbook.Sheets
    xName = xWs.Range(xRngAddress).Value
    If xName <> "" Then
        xInt = 0
        Set xSSh = Nothing
        Set xSSh = Worksheets(xName)
        While Not (xSSh Is Nothing)
            Set xSSh = Nothing
            Set xSSh = Worksheets(xName & "(" & xInt & ")")
            xInt = xInt + 1
        Wend
        If xInt = 0 Then
            xWs.Name = xName
        Else
            If xWs.Name <> xName Then
                xWs.Name = xName & "(" & xInt & ")"
            End If
        End If
    End If
Next
Application.ScreenUpdating = True
End Sub

4。 按 F5 运行VBA代码的键。 然后,所有工作表已按每个相对的A1单元格值重命名。

doc重命名工作表2


如果你有 Kutools for Excel,则无需保存VBA代码,可以使用 重命名多个工作表 功能可以根据所有工作表的相对单元快速重命名。

Kutools for Excel, 与超过 300 方便的功能,使您的工作更加轻松。 

免费安装 Kutools for Excel,请执行以下操作:

1.启用要重命名其工作表名称的工作簿。

2。 点击 Kutools 加 > 工作表 > 重命名工作表。 看截图:

doc重命名工作表11

3.然后在弹出的对话框中,选中要重命名的工作表 工作表 窗格,然后选择其中之一 重命名选项 您需要,在这里我将替换工作表名称,然后检查 重命名具有特定单元格的工作表,然后选择您要重命名的单元格。 看截图:

doc重命名工作表9

4。 点击 Ok。 现在,工作表已使用特定的单元格内容重命名。

doc重命名工作表2

但是有时候,您需要根据一系列单元格值重命名多个工作表,如下图所示,在这种情况下,您可以选择 下面的方法.

doc重命名工作表3


重命名多个工作表 of Kutools for Excel,您还可以根据所选范围重命名工作表。

免费安装 Kutools for Excel,请执行以下操作:

1。 点击 Kutools 加 > 工作表 > 重命名工作表。 看截图:

doc重命名工作表11

2.在 重命名多个工作表 对话框中,您需要指定以下设置:

(1)选择需要从中重命名的工作表 工作表清单;

(2)检查 从特定范围 选项,然后选择您需要基于其重命名的单元格值;

(3)指定 重命名选项,你可以检查 在原始工作表名称之前插入, 在原始工作表名称后插入替换原始工作表名称,您可以在对话框中预览相应的结果。

doc重命名工作表10

3。 点击 Ok,然后您可以看到所选的所有工作表已根据指定的单元格值进行了重命名。

替换原始工作表名称

doc重命名工作表6

在原始工作表名称之前插入

doc重命名工作表7

在原始工作表名称后插入

doc重命名工作表8

使用“重命名工作表”实用程序,您还可以使用特定的前缀或后缀来重命名工作表。 单击此处以了解有关重命名多个工作表的更多信息。

最佳办公生产力工具

🤖 Kutools 人工智能助手:基于以下内容彻底改变数据分析: 智能执行   |  生成代码  |  创建自定义公式  |  分析数据并生成图表  |  调用 Kutools 函数...
热门特色: 查找、突出显示或识别重复项   |  删除空白行   |  合并列或单元格而不丢失数据   |   不使用公式进行四舍五入 ...
超级查询: 多条件VLookup    多值VLookup  |   跨多个工作表的 VLookup   |   模糊查询 ....
高级下拉列表: 快速创建下拉列表   |  依赖下拉列表   |  多选下拉列表 ....
列管理器: 添加特定数量的列  |  移动列  |  切换隐藏列的可见性状态  |  比较范围和列 ...
特色功能: 网格焦点   |  设计图   |   大方程式酒吧    工作簿和工作表管理器   |  资源库 (自动文本)   |  日期选择器   |  合并工作表   |  加密/解密单元格    按列表发送电子邮件   |  超级筛选   |   特殊过滤器 (过滤粗体/斜体/删除线...)...
前 15 个工具集12 文本 工具 (添加文本, 删除字符,...)   |   50+ 图表 类型 (甘特图,...)   |   40+ 实用 公式 (根据生日计算年龄,...)   |   19 插入 工具 (插入二维码, 从路径插入图片,...)   |   12 转化 工具 (小写金额转大写, 货币兑换,...)   |   7 合并与拆分 工具 (高级组合行, 分裂细胞,...)   |   ... 和更多

使用 Kutools for Excel 增强您的 Excel 技能,体验前所未有的效率。 Kutools for Excel 提供了 300 多种高级功能来提高生产力并节省时间。  单击此处获取您最需要的功能...

产品描述


Office Tab 为 Office 带来选项卡式界面,让您的工作更加轻松

  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
Comments (6)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Every time I look for a VBA routine and find an article like this from you guys, I try the sample code and it NEVER works. It always goes into Debug on the first try. I am starting to believe you deliberately publish poorly written code to drive people to try and purchase your Add-in.
This comment was minimized by the moderator on the site
Hi, Don, the VBA has updated twice, it may be works for most of conditions, but not for the all. 
This comment was minimized by the moderator on the site
In the VBA code example, what changes would be made to select A2 as the cell value rather than A1?
This comment was minimized by the moderator on the site
Hi, Henry, select A2 instead of A1, all sheets will renamed with the value of cell A2.
This comment was minimized by the moderator on the site
'Updateby20150602
This code showing error..............Only works ActiveSheet & RunTime Error 1004 [Object_Worksheet faild]
This comment was minimized by the moderator on the site
Hi, Biplab Das, maybe the original code cannot work at new versions (2013 or later), I have upadated a new code in the tutorial, you could try again.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations