请高手相助,下面的代码是设计一个数据透视表,但红颜色那句代码不知道什么原因,总是提示出错,请高手帮助. Public Sub aaa() Dim wb As Worksheet Dim wsd As Worksheet Dim ptcache As PivotCache Dim pt As PivotTable Dim prange As Range Dim finalrow As Long Set wsd = Worksheets("全息") Set wb = Worksheets("sheet2") For Each pt In wb.PivotTables pt.TableRange2.Clear Next pt finalrow = wsd.Cells(65536, 1).End(xlUp).Row Set prange = wsd.Cells(1, 1).Resize(finalrow, 12) Set ptcache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _ SourceData:=prange.Address) Set pt = ptcache.CreatePivotTable(TableDestination:=wb.Range("A2"), _ TableName:="P") pt.ManualUpdate = True pt.AddFields RowFields:=Array("nsrmc", "nsrsbh"), ColumnFields:="sssq_q" With pt.PivotFields("ynse") .Orientation = xlDataField .Function = xlSum .Position = 1 End With pt.ManualUpdate = False pt.ManualUpdate = True End Sub |