abjectpoet
Technical User
Hi there,
I had a quick look through your FAQ and related subjects and couldn't find what I was looking for. I am a bit pressed for time, so please excuse me if I have missed an existing resource.
Before I explain my problem, a caveat: I am more of an end-user than a developer/programmer. I have limited programming experience and have turned to VBA as it seems the last possibility for solving my dilemma.
Here it is then: I have an Excel spreadsheet that details my organization's critical services, broken down into 14 Worksheets for each division. Each Worksheet contains the exact same table, which each division then populated with their data. I have been asked to consolidate this data on a single pivot table which can be updated as revisions are made to the source data on any Worksheet. I cannot introduce additional software, such as Access or another dedicated database, so I am stuck with an Excel-specific solution.
I quickly discovered that I can not use the Wizard's "Multiple Consolidation Ranges" tool because it spits out the wrong categories (i.e. Row and Column fields). As a workaround, I assigned each Division's table to a named range and fed them into MS Query, creating a New Database from Excel Files data source. I used some basic SQL to select and concatenate all named ranges and then returned the data to Excel as a Pivot.
Great! Except...it wouldn't refresh, making it useless. After doing some internet research, it seemed my problem was that the pivot table was refreshing faster than MS Query could digest the changes to the source data (which contains huge amounts of data). Apparently, the only way around this processing difference was to force MS Query to finish its work before refreshing the data. I would need to design some VBA code to orchestrate the order of processes.
This is where I need help. I've tried a number of different approaches that I found online but my foundational knowledge isn't strong enough at this point and I don't have the time to continue this fruitless trial and error.
In case you need to know, here is the SQL code I used to generate the pivot table:
SELECT * FROM QuebecTable QuebecTable
UNION ALL
SELECT * FROM OntarioTable OntarioTable
UNION ALL
SELECT * FROM NorthernTable NorthernTable
UNION ALL
SELECT * FROM AtlanticTable AtlanticTable
UNION ALL
SELECT * FROM AlbManSaskTable AlbManSaskTable
UNION ALL
SELECT * FROM AABTable AABTable
UNION ALL
SELECT * FROM CFOBTable CFOBTable
UNION ALL
SELECT * FROM CSBTable CSBTable
UNION ALL
SELECT * FROM DMOTable DMOTable
UNION ALL
SELECT * FROM HECSBTable HECSBTable
UNION ALL
SELECT * FROM HPFBTable HPFBTable
UNION ALL
SELECT * FROM LegalTable LegalTable
UNION ALL
SELECT * FROM PACCBTable PACCBTable
UNION ALL
SELECT * FROM SPBTable SPBTable
And here is the VBA code I have been working with. I know it is basic but attempts at streamlining some of the recursive elements haven't been successful, so I have aimed for "basic but functional":
Sub Refresh_Data()
Dim RPB_Q As Worksheet
Dim RPB_O As Worksheet
Dim RPB_N As Worksheet
Dim RPB_BAM As Worksheet
Dim RPB_A As Worksheet
Dim CSB As Worksheet
Dim SPB As Worksheet
Dim PAC As Worksheet
Dim LEG As Worksheet
Dim HEC As Worksheet
Dim HPF As Worksheet
Dim DMO As Worksheet
Dim CFB As Worksheet
Dim AAB As Worksheet
Dim Workshts(13)
With ThisWorkbook
Set RPB_Q = .Worksheets("RAPB-Quebec")
Set RPB_O = .Worksheets("RAPB-Ontario")
Set RPB_N = .Worksheets("RAPB-Northern")
Set RPB_BAM = .Worksheets("RAPB-NCR-BC-AB-MAN")
Set RPB_A = .Worksheets("RAPB-ATL")
Set CSB = .Worksheets("CSB")
Set SPB = .Worksheets("SPB")
Set PAC = .Worksheets("PACCB")
Set LEG = .Worksheets("LEGAL")
Set HEC = .Worksheets("HECSB")
Set HPF = .Worksheets("HPFB")
Set DMO = .Worksheets("DMO ASSOC")
Set CFB = .Worksheets("CFOB")
Set AAB = .Worksheets("AAB")
Set WrkShts(0) = RPB_Q
Set WrkShts(1) = RPB_O
Set WrkShts(2) = RPB_N
Set WrkShts(3) = RPB_BAM
Set WrkShts(4) = RPB_A
Set WrkShts(5) = CSB
Set WrkShts(6) = SPB
Set WrkShts(7) = PAC
Set WrkShts(8) = LEG
Set WrkShts(9) = HEC
Set WrkShts(10) = HPF
Set WrkShts(11) = DMO
Set WrkShts(12) = CFB
Set WrkShts(13) = AAB
End With
For i = 0 To 13
With WrkShts(i).QueryTables(1)
.refresh BackgroundQuery:=False
End With
Next i
ActiveSheet.PivotTables("Consolidated Pivot").Refresh Table
End Sub
I tried a simple debugging code to count the number of query tables on each Worksheet and got back a value of "0".
Any help you could provide would be appreciated. Thanks!
I had a quick look through your FAQ and related subjects and couldn't find what I was looking for. I am a bit pressed for time, so please excuse me if I have missed an existing resource.
Before I explain my problem, a caveat: I am more of an end-user than a developer/programmer. I have limited programming experience and have turned to VBA as it seems the last possibility for solving my dilemma.
Here it is then: I have an Excel spreadsheet that details my organization's critical services, broken down into 14 Worksheets for each division. Each Worksheet contains the exact same table, which each division then populated with their data. I have been asked to consolidate this data on a single pivot table which can be updated as revisions are made to the source data on any Worksheet. I cannot introduce additional software, such as Access or another dedicated database, so I am stuck with an Excel-specific solution.
I quickly discovered that I can not use the Wizard's "Multiple Consolidation Ranges" tool because it spits out the wrong categories (i.e. Row and Column fields). As a workaround, I assigned each Division's table to a named range and fed them into MS Query, creating a New Database from Excel Files data source. I used some basic SQL to select and concatenate all named ranges and then returned the data to Excel as a Pivot.
Great! Except...it wouldn't refresh, making it useless. After doing some internet research, it seemed my problem was that the pivot table was refreshing faster than MS Query could digest the changes to the source data (which contains huge amounts of data). Apparently, the only way around this processing difference was to force MS Query to finish its work before refreshing the data. I would need to design some VBA code to orchestrate the order of processes.
This is where I need help. I've tried a number of different approaches that I found online but my foundational knowledge isn't strong enough at this point and I don't have the time to continue this fruitless trial and error.
In case you need to know, here is the SQL code I used to generate the pivot table:
SELECT * FROM QuebecTable QuebecTable
UNION ALL
SELECT * FROM OntarioTable OntarioTable
UNION ALL
SELECT * FROM NorthernTable NorthernTable
UNION ALL
SELECT * FROM AtlanticTable AtlanticTable
UNION ALL
SELECT * FROM AlbManSaskTable AlbManSaskTable
UNION ALL
SELECT * FROM AABTable AABTable
UNION ALL
SELECT * FROM CFOBTable CFOBTable
UNION ALL
SELECT * FROM CSBTable CSBTable
UNION ALL
SELECT * FROM DMOTable DMOTable
UNION ALL
SELECT * FROM HECSBTable HECSBTable
UNION ALL
SELECT * FROM HPFBTable HPFBTable
UNION ALL
SELECT * FROM LegalTable LegalTable
UNION ALL
SELECT * FROM PACCBTable PACCBTable
UNION ALL
SELECT * FROM SPBTable SPBTable
And here is the VBA code I have been working with. I know it is basic but attempts at streamlining some of the recursive elements haven't been successful, so I have aimed for "basic but functional":
Sub Refresh_Data()
Dim RPB_Q As Worksheet
Dim RPB_O As Worksheet
Dim RPB_N As Worksheet
Dim RPB_BAM As Worksheet
Dim RPB_A As Worksheet
Dim CSB As Worksheet
Dim SPB As Worksheet
Dim PAC As Worksheet
Dim LEG As Worksheet
Dim HEC As Worksheet
Dim HPF As Worksheet
Dim DMO As Worksheet
Dim CFB As Worksheet
Dim AAB As Worksheet
Dim Workshts(13)
With ThisWorkbook
Set RPB_Q = .Worksheets("RAPB-Quebec")
Set RPB_O = .Worksheets("RAPB-Ontario")
Set RPB_N = .Worksheets("RAPB-Northern")
Set RPB_BAM = .Worksheets("RAPB-NCR-BC-AB-MAN")
Set RPB_A = .Worksheets("RAPB-ATL")
Set CSB = .Worksheets("CSB")
Set SPB = .Worksheets("SPB")
Set PAC = .Worksheets("PACCB")
Set LEG = .Worksheets("LEGAL")
Set HEC = .Worksheets("HECSB")
Set HPF = .Worksheets("HPFB")
Set DMO = .Worksheets("DMO ASSOC")
Set CFB = .Worksheets("CFOB")
Set AAB = .Worksheets("AAB")
Set WrkShts(0) = RPB_Q
Set WrkShts(1) = RPB_O
Set WrkShts(2) = RPB_N
Set WrkShts(3) = RPB_BAM
Set WrkShts(4) = RPB_A
Set WrkShts(5) = CSB
Set WrkShts(6) = SPB
Set WrkShts(7) = PAC
Set WrkShts(8) = LEG
Set WrkShts(9) = HEC
Set WrkShts(10) = HPF
Set WrkShts(11) = DMO
Set WrkShts(12) = CFB
Set WrkShts(13) = AAB
End With
For i = 0 To 13
With WrkShts(i).QueryTables(1)
.refresh BackgroundQuery:=False
End With
Next i
ActiveSheet.PivotTables("Consolidated Pivot").Refresh Table
End Sub
I tried a simple debugging code to count the number of query tables on each Worksheet and got back a value of "0".
Any help you could provide would be appreciated. Thanks!