您好我正在处理我的VBA代码,根据源数据的最后一行设置范围,然后在该范围内创建一个数据透视表。但是,当我运行错误1004(应用程序定义错误)的代码时,最后一行出错了。我觉得所有变量都已定义,应该没问题。消息框还为我提供了源数据中最右边的行号。你能帮我解决一下吗?谢谢。
Dim PvtTbl As pivotTable
Dim wsData As Worksheet
Dim rngData As Range
Dim PvtTblCache As PivotCache
Dim wsPvtTbl As Worksheet
Dim pvtFld As PivotField
Set wsData = Worksheets("Task List Data Export")
Set wsPvtTbl = Worksheets("Summary")
wsPvtTbl.Cells.Clear
wsPvtTbl.Cells.ColumnWidth = 10
For Each PvtTbl In wsPvtTbl.PivotTables
If MsgBox("Delete existing PivotTable!", vbYesNo) = vbYes Then
PvtTbl.TableRange2.Clear
End If
Next PvtTbl
Dim last As Long
With Worksheets("Task List Data Export")
last = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
MsgBox last
Set rngData = Worksheets("Task List Data Export").Range(Cells(1, 1), Cells(last, 15))
************************更新********************** ** 嗨,我应用了Dy.Lee的代码,这个错误终于消失了。但是我的下一行再次出错(错误类型不匹配)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=rngData, Version:=xlPivotTableVersion12).CreatePivotTable TableDestination:=wsPvtTbl.Range("B25"), TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion12
任何想法?再次感谢
答案 0 :(得分:1)
代码就像这样
akshay@db-3325:/tmp$ awk -v FS=, -v OFS=, -f pivot_with_order.awk data.txt
,Brand,Color,Gender,Logo,width,Fits,catgegory,primarycolor,size
1,sports,White,Male,yes,10,,,,
4,Running,,,,12,Lose,,,
3,,blue,,,,,shoe,blue,
5,Running,,,,,,,,M