chileverde
New Member
- Joined
- May 18, 2012
- Messages
- 5
Can anyone tell me how to "select all" cells in a macro for a pivot table?
I'm trying to create a macro to build a pivot table based on all the populated cells in a worksheet (Excel 2007), the problem being that dataset will not always be the same size.
I originally built this using the macro recorder, but when I hit "Ctrl-A", the macro actually recorded a defined range of cells. Obviously this won't work when the size of the dataset changes. How can I tell the PivotCaches.Create method to use everything from R1C1 to the last cell for the SourceData (i.e., do the same thing as Ctrl-A)? The bit red is what I need to fix:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlConsolidation, SourceData:= _
Array("Sheet1!R1C1:R16C81"), Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="", TableName:="PivotTable3", _
DefaultVersion:=xlPivotTableVersion12
Thanks in advance,
David
I'm trying to create a macro to build a pivot table based on all the populated cells in a worksheet (Excel 2007), the problem being that dataset will not always be the same size.
I originally built this using the macro recorder, but when I hit "Ctrl-A", the macro actually recorded a defined range of cells. Obviously this won't work when the size of the dataset changes. How can I tell the PivotCaches.Create method to use everything from R1C1 to the last cell for the SourceData (i.e., do the same thing as Ctrl-A)? The bit red is what I need to fix:
ActiveWorkbook.PivotCaches.Create(SourceType:=xlConsolidation, SourceData:= _
Array("Sheet1!R1C1:R16C81"), Version:=xlPivotTableVersion12). _
CreatePivotTable TableDestination:="", TableName:="PivotTable3", _
DefaultVersion:=xlPivotTableVersion12
Thanks in advance,
David