Pivot Table with variable # of columns

G

Guest

I am trying to create a pivot table using VBA and will have a different
amount of data columns each month. In January, for example, i will only have
January, but in February, i will have january and February and so forth. So
far, i haven't found a way to do it.

Any help would be greatly appreciated.
Thanks!
 
D

Debra Dalgleish

You could use the address of the current region, e.g.:

Dim rng As Range

Set rng = Worksheets("Data").Range("A1").CurrentRegion
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=rng.Address).CreatePivotTable _
TableDestination:="", TableName:="PivotTable1"
 

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

Top