|
Sheets("Sheet1").Select
Dim strSourceData As String, iR As Integer, iC As Integer, iR1 As Integer, PTname As String
iR = Sheets("Sheet1").Range("A65536").End(xlUp).Row '获取Sheet1表最下行的行名称
iC = Sheets("Sheet1").Range("IV1").End(xlToLeft).Column '获取Sheet1最右列的列名称
iR1 = Sheets("透视表").Range("A65536").End(xlUp).Row + 1 '获取透视表最下行+1的行名称
PTname = Format(VBA.Date, "WW") & "周透视表" '生成TableName的参数(String格式)
strSourceData = "Sheet1!R1C1:R" & iR & "C" & iC '生成SourceData的参数(String格式)
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
strSourceData, Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:=Sheets("透视表").Cells(iR1, 1), TableName:=PTname, DefaultVersion:= _
xlPivotTableVersion10
ActiveSheet.PivotTables(PTname).AddDataField ActiveSheet.PivotTables( _
PTname).PivotFields("套数"), "求和项:套数", xlSum
运行到上面时弹出“不能取得类Worksheet的PivoTable属性”,是不是我的名称写错了?
如何引用名称为变量的数据透视表呢?
至此为止,下面是录的还没改
ActiveSheet.PivotTables("数据透视表20").AddDataField ActiveSheet.PivotTables( _
"数据透视表20").PivotFields("建筑面积(㎡)"), "求和项:建筑面积(㎡)", xlSum
With ActiveSheet.PivotTables("数据透视表20").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
接触vba时间短没什么基础,都是需要哪部分就度娘,请大神指点迷津,不胜感激
|
|