excel - “您为工作表或图表输入了无效名称”,需要更新代码
问题描述
当我的“复制数据透视表”代码创建数据透视表时,我有一个带有“/”的品牌。一旦发现它调试并停止创建数据透视表,excel 中的选项卡就不能用“/”创建/命名。是否有我可以包含的代码告诉它当它看到“RE/DONE”时将名称更改为“RE DONE”,这样它就可以在不调试的情况下创建数据透视表。我的代码如下。
On Error GoTo errHandler
Application.DisplayAlerts = False
Dim ws As Worksheet
Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
Dim strPF As String
Dim strPI As String
Set ws = Sheets("Invoice PVTTBL Template")
Set pt = ws.PivotTables(1)
Set pf = pt.PageFields(1)
strPF = pf.Name
For Each pi In pf.PivotItems
strPI = Left(pi.Name, 31)
On Error Resume Next
Sheets(strPI).Delete
On Error GoTo 0
ws.Copy After:=Sheets(Sheets.Count)
With ActiveSheet
.Name = strPI
With .PivotTables(1).PivotFields(strPF)
.PivotItems(pi.Name).Visible = True
.CurrentPage = pi.Name
End With
End With
Next pi
ws.Activate
MsgBox "Invoices Created"
exitHandler:
Application.DisplayAlerts = True
Exit Sub
errHandler:
MsgBox "Could not create sheets"
Resume exitHandler
End Sub
解决方案
推荐阅读
- c++ - c++中从double到string的转换
- python - Numpy:基于列中的匹配连接/扩展二维数组。如何消除for循环?
- python - 无法使用 Pytorch 从谷歌 AI 平台获取预测
- ios - 无法为 iOS xCode 项目安装 Firebase
- go - 谷歌云函数默认环境变量未设置
- c# - 创建实体时的表名(包含/正则表达式) - 实体框架 - 表前缀
- c++ - vector.push_back(vector.back()+1) 是未定义的行为吗?
- pine-script - 我怎样才能把这个 PineScript 输入变成一个可用的函数?
- powershell - 为 powershell 中的参数提供值
- android - 知道链接从 Firebase 存储下载图像