Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi, I am trying to create a pivot table with vba by passing rowfields,
columnfields, and pagefields as variables. The code below works if I have a single value as for the columnfield or for the rowfield. But for pagefields, I need to pass two values (as in Line#13). I would like to use Line#12 but am not sure how to get pass the two values to the pfd variable. Thanks! Dim rfd As Variant Dim cfd As Variant Dim pfd As Variant Line#1 Sub Macro4() Line#2 rfd = "Date" Line#3 cfd = "SKU" Line#4 pfd = "" & "Region" & """" & "," & """" & "Franchise Store" & "" Line#5 Line#6 ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _ Line#7 "'SourceData (2)'!R1C1:R5000C5").CreatePivotTable TableDestination:="", _ Line#8 TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion10 Line#9 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) Line#10 ActiveSheet.Cells(3, 1).Select Line#11 ActiveSheet.PivotTables("PivotTable3").AddFields RowFields:=rfd, _ Line#12 ColumnFields:=cfd, PageFields:=Array(pfd) Line#13 'ColumnFields:=cfd, PageFields:=Array("Franchise Store", "Region") Line#14 ActiveSheet.PivotTables("PivotTable3").PivotFields ("Inventory").Orientation = _ Line#15 xlDataField Line#16 End Sub |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Since excel is looking for an array, you have to pass it an array. The
array(pfd) you're passing is a single element of that long string--not two elements (of shorter strings). Why not: Dim pfd as Variant pfd = array("Region", "Franchise Store") ...., PageFields:=Array(pfd) klingongardener wrote: Hi, I am trying to create a pivot table with vba by passing rowfields, columnfields, and pagefields as variables. The code below works if I have a single value as for the columnfield or for the rowfield. But for pagefields, I need to pass two values (as in Line#13). I would like to use Line#12 but am not sure how to get pass the two values to the pfd variable. Thanks! Dim rfd As Variant Dim cfd As Variant Dim pfd As Variant Line#1 Sub Macro4() Line#2 rfd = "Date" Line#3 cfd = "SKU" Line#4 pfd = "" & "Region" & """" & "," & """" & "Franchise Store" & "" Line#5 Line#6 ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _ Line#7 "'SourceData (2)'!R1C1:R5000C5").CreatePivotTable TableDestination:="", _ Line#8 TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion10 Line#9 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) Line#10 ActiveSheet.Cells(3, 1).Select Line#11 ActiveSheet.PivotTables("PivotTable3").AddFields RowFields:=rfd, _ Line#12 ColumnFields:=cfd, PageFields:=Array(pfd) Line#13 'ColumnFields:=cfd, PageFields:=Array("Franchise Store", "Region") Line#14 ActiveSheet.PivotTables("PivotTable3").PivotFields ("Inventory").Orientation = _ Line#15 xlDataField Line#16 End Sub -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() Dave: Thank you so much. Your solution works beautifully. Merry X'Mas! Dave Peterson wrote: Since excel is looking for an array, you have to pass it an array. The array(pfd) you're passing is a single element of that long string--not two elements (of shorter strings). Why not: Dim pfd as Variant pfd = array("Region", "Franchise Store") ..., PageFields:=Array(pfd) klingongardener wrote: Hi, I am trying to create a pivot table with vba by passing rowfields, columnfields, and pagefields as variables. The code below works if I have a single value as for the columnfield or for the rowfield. But for pagefields, I need to pass two values (as in Line#13). I would like to use Line#12 but am not sure how to get pass the two values to the pfd variable. Thanks! Dim rfd As Variant Dim cfd As Variant Dim pfd As Variant Line#1 Sub Macro4() Line#2 rfd = "Date" Line#3 cfd = "SKU" Line#4 pfd = "" & "Region" & """" & "," & """" & "Franchise Store" & "" Line#5 Line#6 ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:= _ Line#7 "'SourceData (2)'!R1C1:R5000C5").CreatePivotTable TableDestination:="", _ Line#8 TableName:="PivotTable3", DefaultVersion:=xlPivotTableVersion10 Line#9 ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1) Line#10 ActiveSheet.Cells(3, 1).Select Line#11 ActiveSheet.PivotTables("PivotTable3").AddFields RowFields:=rfd, _ Line#12 ColumnFields:=cfd, PageFields:=Array(pfd) Line#13 'ColumnFields:=cfd, PageFields:=Array("Franchise Store", "Region") Line#14 ActiveSheet.PivotTables("PivotTable3").PivotFields ("Inventory").Orientation = _ Line#15 xlDataField Line#16 End Sub -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Display the source for a pivot table page field | Excel Worksheet Functions | |||
String parsing with variable lenght strings | Excel Worksheet Functions | |||
how do I make single character as a variable in an array | Excel Worksheet Functions | |||
last number array from string | Excel Worksheet Functions | |||
Formula to list unique values | Excel Worksheet Functions |