1
我已經在VBA中創建了一個包含字符串數據的數據透視表,但似乎無法摺疊數據透視表中的所有字段,我該怎麼做? 這裏是我的源代碼VBA數據透視表摺疊所有字段
SrcData = ActiveSheet.Name & "!" & Range(Cells(1, 1), Cells(46, 3)).Address(ReferenceStyle:=xlR1C1)
StartPvt = Sheets("Key Controls").Cells(2, 5).Address(ReferenceStyle:=xlR1C1)
Set pvtCache = ActiveWorkbook.PivotCaches.Create(_
SourceType:=xlDatabase, _
SourceData:=SrcData)
Set pvt = pvtCache.CreatePivotTable(_
TableDestination:=StartPvt, _
TableName:="PivotTable1")
pvt.PivotFields("SOP Reference").Orientation = xlRowField
pvt.PivotFields("Key Control ID").Orientation = xlRowField
pvt.PivotFields("Key Control Name").Orientation = xlRowField
行字段的方向應是持倉量也。防爆。 'With ActiveSheet.PivotTables(「PivotTable3」)。PivotFields(「Key Control ID」) .Orientation = xlRowField .Position = 2 End With'假設你想將整個字段摺疊爲「SOP Reference」選擇一個合適的單元格say 'A15'code將爲'Range(「A15」)。選擇 ActiveSheet.PivotTables(「PivotTable3」)。PivotFields(「Key Control Name」)。 _ PivotItems(「electron」)。DrillTo「SOP Reference」'您的表格[看起來像](https://www.dropbox.com/s/51znhaab1z0lnno/pivot_q070716.xlsm?dl=0) – skkakkar