Make a copy of some of the columns in a worksheet

How to use cDataSet.bigCommit() to create a copy of the values in a sheet, re-ordering and/or only copying some of the columns

In Make a copy of a worksheet we looked at how to use the .bigCommit() method of  cDataSet  to copy a table from one worksheet to another.  In Make a filtered copy of a worksheet we looked at how to filter that data by particular values. This method is also capable of changing the order of columns or omitting some of them. Here's how to copy and reorder just a few columns (of course this can also be combined with filtering).

VBA

Public Sub straightCopySome()
    Dim ds As New cDataSet
    ds.populateData(wholeSheet("geoCoding")).bigCommit _
            wholeSheet("messAround"), True, Array("city", "country", "input address")

End Sub

Google Apps Script

In this example, I am going to assume now that you are using cDataSet from an external library rather than from a local copy. You will see that we are using the functions from the Mcpher namespace.
function straightCopySome() {
  new Mcpher
      .cDataSet() 
      .populateData(Mcpher.wholeSheet("Test"))
      .bigCommit(Mcpher.wholeSheet("messAround"),true,["city", "country", "input address"]);
}



Take a look at One Liners for more tips like this. In the meantime why not join our forum,follow the blog or follow me on twitter to ensure you get updates when they are available.

You want to learn Google Apps Script?

Learning Apps Script, (and transitioning from VBA) are covered comprehensively in my my book, Going Gas - from VBA to Apps script, available All formats are available now from O'Reilly,Amazon and all good bookshops. You can also read a preview on O'Reilly

If you prefer Video style learning I also have two courses available. also published by O'Reilly.
Google Apps Script for Developers and Google Apps Script for Beginners.







Comments