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.
123456789101112 Sub consolidate()Dim dst As cDataSet, ds As cDataSet, n As Long, dc As cCellSet dst = New cDataSetdst.populateData wholeSheet("inputs"), , , , , , Truen = 0For Each dc In dst.Column("names").RowsSet ds = New cDataSetds.populateData wholeSheet(dc.toString), , dc.toString, , , , Truen = n + ds.bigCommit(wholeSheet("consolidated").Offset(n), n = 0, , , , , n = 0)Set ds = NothingNext dcEnd Sub
For more usages of data abstraction, please visit ramblings.mcpher.com.