excel - 运行时错误“1004”无法获取数据透视表类的 PivotFields 属性
问题描述
我开发了一个宏,它会自动生成报告,但使用某种类型的数据我收到了错误。我尝试了几件事,但我没有设法解决它,所以我寻求一些帮助。,这是有问题的行:Fin = .PivotTables(1).PivotFields("Account Owner").VisibleItems.Count
这是完整的代码:
Sub Generar_informes()
Dim i As Double
Dim Ini As Double
Dim Fin As Double
'Desactivamos actualización de pantalla
Application.ScreenUpdating = False
Sheets("Pivot Table").Select
With Sheets("Pivot Table")
'indicamos la fila siguiente a la primera fila con datos
Ini = Columns(1).Range("A1").End(xlDown).Row
'Contamos los todas los comerciales de la tabla dinámica1
Fin = .PivotTables(1).PivotFields("Account Owner").VisibleItems.Count
'Inciamos un bucle donde por cada comercial generamos informe
For i = 1 To Fin
'para mostrar el informe debemos hacer referencia a los campos de valores
.Cells(i + Ini, 2).ShowDetail = True
'Nombramos la pestaña con el nombre del comercial.
ActiveSheet.Name = .Cells(i + Ini, 1).Value
'Seleccionamos la hoja con el detalle del comercial
ActiveSheet.Select
'Movemos la hoja a un libro nuevo
ActiveSheet.Move
'Cambiamos color de celdas a modificar por los comerciales
Range("L1:N1").Interior.Color = RGB(255, 153, 0)
'Agregamos la lista desplegable
Columns("N:N").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="Director,Manager,Owner,Staff,Top Executive(Chairman-Chief-etc),Vice President/SVP/EVP"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & ActiveSheet.Name
ActiveWorkbook.Close False
Next i
End With
Application.ScreenUpdating = True
MsgBox "¡Reportes generados exitosamente!"
End Sub
谢谢先进
解决方案
推荐阅读
- python - 是否创建了两个不同的模块来存储 __name__ 变量的信息?
- javascript - 表单根据 React 中的按钮类型独立提交
- python - Flask SQLAlchemy:从数组中选择所有具有 ID 的行
- python - 试图计算单词,只计算最后一个列表
- sql-server - T-SQL:从字段中的列表中搜索特定字符串
- download - Tabulator & SheetJS - 分组列标题在下载时未正确显示
- linux - windows中的linux子系统在无人登录的情况下是否也会运行?
- python - 组合两个“for”循环 - ValueError: no enough values to unpack (expected 3, got 1)
- java - 在 Cmake 中使用 Swig 不能正确链接 Java
- python - 使用 Dask 转换双列表推导