Excel 根据不同选项卡上的单元格值重命名选项卡
我的工作簿有14个选项卡。我想重命名其中4个选项卡。要重命名的选项卡将在不包含非法字符或长度限制的其他选项卡上使用单元格值 我进行了研究,但只发现单元格值在每个工作簿的同一位置 如果单元格值为空或0,我想隐藏选项卡 要重命名的工作表:Excel 根据不同选项卡上的单元格值重命名选项卡,excel,vba,Excel,Vba,我的工作簿有14个选项卡。我想重命名其中4个选项卡。要重命名的选项卡将在不包含非法字符或长度限制的其他选项卡上使用单元格值 我进行了研究,但只发现单元格值在每个工作簿的同一位置 如果单元格值为空或0,我想隐藏选项卡 要重命名的工作表: 摘要1 摘要(2) 摘要(3) 摘要(4) 具有用于重命名的单元格值的工作表: 总体总结 汇总表1的单元格A24 单元格A25用于汇总(2) 单元格A26用于汇总(3) 单元格A27用于汇总(4) 等等 对于有空格的单元格,必须小心隐藏,因为可能有多个
- 摘要1
- 摘要(2)
- 摘要(3)
- 摘要(4)
- 总体总结
- 汇总表1的单元格A24
- 单元格A25用于汇总(2)
- 单元格A26用于汇总(3)
- 单元格A27用于汇总(4)
If Sheets("Overall Summary").Range("A24").Value = <> then
For Each ws In ThisWorkbook.Worksheets
If InStr(1, ws.Name, "Hide_", vbTextCompare) Then
i = i + 1
End If
Next ws
Sheets("OldName").Name = "Hide_" & i
End If
如果工作表(“总体汇总”).范围(“A24”).值=然后
对于此工作簿中的每个ws。工作表
如果InStr(1,ws.Name,“隐藏”,vbTextCompare),则
i=i+1
如果结束
下一个ws
图纸(“OldName”).Name=“隐藏”&i
如果结束
这一款有望满足您的需求
它查看活动工作簿中的每个工作表
,如果名称包含摘要
,它将下移到总体摘要
工作表的A列
,并尝试获取要添加的新名称
如果它在“总体摘要”
中查看的单元格为0或空白,它会将该摘要工作表重命名为“隐藏X”
,但请注意,它可以为您隐藏工作表:)
你可以试试这个
Sub Trythis()
Dim cell As Range
For Each cell in Worksheets("Overall Summary").Range("A24:A27") ‘ loop through relevant range of “Overall Summary” sheet
If Not IsEmpty(cell) And cell.Value <> 0 Then ‘ if current cell isn’t neither empty nor zero
Select Case cell.Row ‘check for current cell value and act accordingly
Case 24
Sheets("Summary 1").Name = cell.Value
Case 25
Sheets("Summary (2)").Name = cell.Value
Case 26
Smeets("Summary (3)").Name = cell.Value
Case 27
Sheets("Summary (4)").Name = cell.Value
End Select
End If
Next
End Sub
Sub-Trythis()
暗淡单元格作为范围
对于工作表中的每个单元格(“总体汇总”)。范围(“A24:A27”)循环浏览“总体汇总”表的相关范围
如果不是IsEmpty(单元格)和cell.Value 0,则“如果当前单元格既不是空的也不是零的”
选择Case cell.Row'检查当前单元格值并相应地执行操作
案例24
表格(“摘要1”)。名称=单元格。值
案例25
工作表(“摘要(2)”)。名称=单元格。值
案例26
Smeets(“摘要(3)”)。名称=单元格。值
案例27
表格(“摘要(4)”)。名称=单元格。值
结束选择
如果结束
下一个
端接头
@Hery0502,有什么反馈吗?
Sub RenameSummary()
Dim objRegex
Set objRegex = CreateObject("vbscript.regexp")
Dim offset As Long
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If InStr(LCase$(ws.name), "summary") > 0 Then
With objRegex
.Global = True
.Pattern = "[^\d]+"
offset = CLng(.Replace(ws.name, vbNullString))
End With
With sheets("Overall Summary").Range("A" & (23 + offset))
If Len(.Value2) = 0 Or .Value2 = 0 Then
ws.name = "HIDE " & .row
'ws.Visible = xlSheetHidden 'can directly hide sheet
Else
ws.name = .Value2
End If
End With
End If
Next ws
End Sub
Sub Trythis()
Dim cell As Range
For Each cell in Worksheets("Overall Summary").Range("A24:A27") ‘ loop through relevant range of “Overall Summary” sheet
If Not IsEmpty(cell) And cell.Value <> 0 Then ‘ if current cell isn’t neither empty nor zero
Select Case cell.Row ‘check for current cell value and act accordingly
Case 24
Sheets("Summary 1").Name = cell.Value
Case 25
Sheets("Summary (2)").Name = cell.Value
Case 26
Smeets("Summary (3)").Name = cell.Value
Case 27
Sheets("Summary (4)").Name = cell.Value
End Select
End If
Next
End Sub