ปัญหาทำpivat table จากข้อมูลที่เป็นไดนามิก
Posted: Sun Aug 31, 2014 9:17 pm
โค๊ดก่อนนะครับ
ปัญหาก็คือ
เพราะข้อมูลจริงๆอยากได้ที่เป็นไดนาทิกไม่เหมือนกันทุกวัน แต่ในโค๊ดมันเป็น R1C1:R42C6 ซึ่งไม่ใช่นานามิก เลยอยากรู้ว่าต้องแก้ยังไงครับ
Code: Select all
Sub Macro1()
'
' Macro1 แมโคร
'
'
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet2!R1C1:R42C6", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet4!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("ที่")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("มหาลัย"), "นับจำนวน ของ มหาลัย", xlCount
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("ย่อ"), "นับจำนวน ของ ย่อ", xlCount
With ActiveSheet.PivotTables("PivotTable1").PivotFields("เกิด")
.Orientation = xlColumnField
.Position = 2
End With
End Subปัญหาก็คือ
Code: Select all
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Sheet2!R1C1:R42C6", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Sheet4!R3C1", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14