Excel中VBA创建透视表时提示"类型不匹配",麻烦大侠看看
具体程序如下:Sub整理场景数据_按钮1_Click()DimwkAsWorkbookDimwknameAsStringDimsourcerangeAsRangeDimn...
具体程序如下:
Sub 整理场景数据_按钮1_Click()
Dim wk As Workbook
Dim wkname As String
Dim sourcerange As Range
Dim newrange As Range
Dim ptc As PivotCache
Dim pvc As PivotTable
Dim r As Integer
Sheets.Add after:=Sheets("场景数据")
ActiveSheet.Name = "G"
For Each wk In Workbooks
If wk.Name Like "2 3 4G流量*" Then wkname = wk.Name
Next
r = Workbooks(wkname).Worksheets("2G小区日均").Range("A65536").End(xlUp).Row
Set sourcerange = Workbooks(wkname).Worksheets("2G小区日均").Cells(1, 1).Resize(r, 6)
Set newrange = Workbooks("23G数据流量整理").Worksheets("G").Range("A1")
Set ptc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=sourcerange, Version:=xlPivotTableVersion12) '这一句提示[运行错误’13‘:类型不匹配]
Set pvc = ptc.CreatePivotTable(TableDestination:=newrange, TableName:="数据透视表1", DefaultVersion:=xlPivotTableVersion12)
With ActiveSheet.PivotTables("数据透视表1").PivotFields("场景")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("行标签"), "计数项:行标签", xlCount 展开
Sub 整理场景数据_按钮1_Click()
Dim wk As Workbook
Dim wkname As String
Dim sourcerange As Range
Dim newrange As Range
Dim ptc As PivotCache
Dim pvc As PivotTable
Dim r As Integer
Sheets.Add after:=Sheets("场景数据")
ActiveSheet.Name = "G"
For Each wk In Workbooks
If wk.Name Like "2 3 4G流量*" Then wkname = wk.Name
Next
r = Workbooks(wkname).Worksheets("2G小区日均").Range("A65536").End(xlUp).Row
Set sourcerange = Workbooks(wkname).Worksheets("2G小区日均").Cells(1, 1).Resize(r, 6)
Set newrange = Workbooks("23G数据流量整理").Worksheets("G").Range("A1")
Set ptc = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=sourcerange, Version:=xlPivotTableVersion12) '这一句提示[运行错误’13‘:类型不匹配]
Set pvc = ptc.CreatePivotTable(TableDestination:=newrange, TableName:="数据透视表1", DefaultVersion:=xlPivotTableVersion12)
With ActiveSheet.PivotTables("数据透视表1").PivotFields("场景")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _
).PivotFields("行标签"), "计数项:行标签", xlCount 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询