Lets say you have an Excel workbook consisting of tabs, all in the same format, that various people completed. You want to copy them all to a consolidated sheet from time to time so you can do pivot tables etc.
I’ve talked about abstracting Excel data on this blog several times, and also introduced you to some tools to make that available. Using cDataSet, you can solve this consolidation problem in just a few lines of code.
First make a list of the sheets you want to concatenate. In this case I’ve listed out them in a tab called ‘inputs’, in a column called ‘names’, and create a new sheet called ‘consolidated’.
Executing this code will then take each of those sheets mentioned in the names column and consolidate them.
Sub consolidate() Dim dst As cDataSet, ds As cDataSet, n As Long, dc As cCell Set dst = New cDataSet dst.populateData wholeSheet("inputs"), , , , , , True n = 0 For Each dc In dst.Column("names").Rows Set ds = New cDataSet ds.populateData wholeSheet(dc.toString), , dc.toString, , , , True n = n + ds.bigCommit(wholeSheet("consolidated").Offset(n), n = 0, , , , , n = 0) Set ds = Nothing Next dc End Sub
For more usages of data abstraction, please visit ramblings.mcpher.com.