Excel宏运行时错误424

您所在的位置:网站首页 宏运行错误424 Excel宏运行时错误424

Excel宏运行时错误424

2024-04-14 06:48| 来源: 网络整理| 查看: 265

我很少需要创建透视表编程如此,让这是怎么回事我创建了一个小分来逐步了解:

Sub CreatePivotOnNewSheet() Sheets.Add ActiveSheet.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ ActiveSheet.Range("A1").CurrentRegion, Version:= _ xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet1!R3C1", _ TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12 End Sub

This compiles OK but throws an error 438: Object doesn't support this property or method. I searched the Object Browser for PivotCaches and found that it is a member of Workbook and PivotTable. It isn't a member of Worksheets! This makes sense when you consider that pivot tables on different sheets can use the same pivot cache.

所以,改变代码:

Sub CreatePivotOnNewSheet() Sheets.Add ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ ActiveSheet.Range("A1").CurrentRegion, Version:= _ xlPivotTableVersion12).CreatePivotTable TableDestination:="Sheet1!R3C1", _ TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12 End Sub

,现在我们得到一个运行时错误:

no data for pivot table

哪个需要更大才能显示完整的原因(谢谢微软!),但我想它继续说对至少包含两行的范围的引用,并且其顶部行中没有空白单元格。在中断模式下,我去了新添加的工作表并创建了一个2x2的数据表。回到IDE中,按下F8并且它工作正常,尽管数据透视表没有定义任何行/列等。我没有试图测试你的剩余代码,这似乎创造了定义 - 我会把它留给你。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3