VBA Routine only pulling subset of records

mhenk

Well-known Member
Joined
Jun 13, 2005
Messages
591
Hey all -

I'm using the following code to create a pivot table based off of three identically set up worksheets (different quarters of the same data).

Code:
Option Explicit

Sub MultipleSheetPTs()

Dim i As Long
Dim objPivotCache As PivotCache
Dim objRS As Object
Dim wbknew As Workbook
Dim wks As Worksheet
Dim arSQL() As String

With ActiveWorkbook
    ReDim arSQL(1 To .Worksheets.Count)
    For Each wks In .Worksheets
        i = i + 1
        arSQL(i) = "SELECT * From [" & wks.Name & "$]"
    Next wks

Set wks = Nothing
Set objRS = CreateObject("ADODB.Recordset")

objRS.Open Join$(arSQL, " UNION ALL "), Join$(Array("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", .FullName, ";Extended Properties=""Excel 8.0;"""), vbNullString)

objRS.Open Join$(arSQL, " UNION ALL "), Join$(Array("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", .FullName, ";Extended Properties=""Excel 8.0;"""), vbNullString)

End With

Set wbknew = Workbooks.Add(template:=xlWBATWorksheet)

With wbknew
    Set objPivotCache = .PivotCaches.Add(xlExternal)
    Set objPivotCache.Recordset = objRS
    Set objRS = Nothing

    With .Worksheets(1)
        objPivotCache.CreatePivotTable TableDestination:=.Range("A1")
    Set objPivotCache = Nothing
    Range("A1").Select
End With
End With
Set wbknew = Nothing
End Sub

The code works great, except for the small fact that it's only pulling the first 12,218 records of each worksheet in the source file.

Is this a vba limitation? A pivot table limitation?

Let me know if you can lend me a hand. Thanks much.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,191,070
Messages
5,984,455
Members
439,889
Latest member
mukundghayadar1983

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top