How Can I pull data from multiple tabs into one google sheet via Google App Script

Viewed 240

All,

Before I explain the problem, I would like to present some information about what it is that I am working with.

Tab 1 can have columns: Date, State,Actual/Forecast,Value

Tab 2 can have columns: Date, Actual/Forecast, Value

Tab 3 will have: Date, Actual/Forecast, Value

I need to pull date, actual/forecast, and value columns from tabs 1 and 2 and populate into tab 3 in a proper table format without any blank rows/breaks for column A. I would ideally like to do this by the click of a button on tab 3. How would I go about doing this? I found that I could copy over one sheet's data via:

function MoveData() {
var ss = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet1");
var ss3 = 
SpreadsheetApp.getActiveSpreadsheet().getSheetByName("sheet3");
ss.getRange("A2:A").copyTo(ss3.getRange("A2"), {contentsOnly:true});
ss.getRange("C2:C").copyTo(ss3.getRange("B2"), {contentsOnly:true});
ss.getrange("D2:D").copyTo(ss3.getrange("C2"), {contentsOnly:true});
}

The next step would be to populate data from the second sheet right below what is being pulled via this function.

Any and all help would be greatly appreciated.

1 Answers
Related