How do you build pivot table in VB

G

Guest

I saved a macro that builds a given pivot table in excel and is shown below. Question is how do I change this so that the "SourceData" range can be given in row number, column number format rather than what's shown

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=
"Sheet1!R1C1:R29C20").CreatePivotTable TableDestination:="", TableName:=
"PivotTable1
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1
ActiveSheet.Cells(3, 1).Selec
With ActiveSheet.PivotTables("PivotTable1"
.ColumnGrand = Fals
.RowGrand = Fals
.SmallGrid = Fals
End Wit
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("WMW", "WML"
, "COIL HGT"), ColumnFields:="Run#
ActiveSheet.PivotTables("PivotTable1").PivotFields("Qty").Orientation =
xlDataFiel
Range("B7").Selec
Selection.Delet
Range("A7").Selec
Selection.Delet
 
D

Dave Peterson

I just set it to my range:

dim myRng as range
with worksheets("sheet1")
set myRng = .range("a1:T" & .cells(.rows.count,"A").end(xlup).row)
end with

later....

....sourcedata:=myrng.address(external:=true).....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Pivot table help 8
Format Pivot total rows 2
Pivot table 2
PivotTable Macro not working 2
Invalid Procedure call or argument 1
Named argument not found 1
Pivot Table Error 1
pivot table range selection 2

Top