Hello!
I have created the code below in order to have a pivot table automatically, but something is not working properly.
I suppose it is a problem related to high number of rows (up to 100k) because when I change the range of the cache to 200 rows it works!
Sorry, I forget to mention! I am working with Excel 2010!
I have created the code below in order to have a pivot table automatically, but something is not working properly.
Rich (BB code):
Sub DBPivotTables()
Dim lrowdb As Long
lrowdb = ActiveWorkbook.Sheets("db_tr").Cells(Rows.Count, 1).End(xlUp).Row
Dim rangesodt As Range
Set rangesodt = ActiveWorkbook.Sheets("db_tr").Range("a1:h" & lrowdb)
Dim rangegr As Range
Set rangegr = ActiveWorkbook.Sheets("db_tr").Range("a1:e" & lrowdb)
Dim rangesch As Range
Set rangesch = ActiveWorkbook.Sheets("db_tr").Range("a1:g" & lrowdb)
Dim sodtpt As PivotTable
Dim sodtcache As PivotCache
Dim sodtfields As PivotField
Dim sodtitems As PivotItem
On Error Resume Next
Sheets("sodt_tr").Select
ActiveSheet.PivotTables("sodt").TableRange2.Clear
Sheets("db_tr").Select
Set sodtcache = ActiveWorkbook.PivotCaches.Create(xlDatabase, rangesodt)
Sheets("sodt_tr").Select
Set sodtpt = ActiveSheet.PivotTables.Add(sodtcache, Range("a2"), "sodt")
With sodtpt
.PivotFields("pn").Orientation = xlRowField
.PivotFields("so dt").Orientation = xlDataField
End With
End Sub
I suppose it is a problem related to high number of rows (up to 100k) because when I change the range of the cache to 200 rows it works!
Sorry, I forget to mention! I am working with Excel 2010!
Last edited by a moderator: