Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9626

Using a list of ID's and a List of conditions COPY and Paste

$
0
0

I have a spreadsheet a list of 15 spreadsheet that I have to update weekly with fresh data.

At present I do this manually however having a script will make the task so much easier.

What I have is a spreadsheet that contains the master data, with a separate tab that contains a list of the spreadsheet ID's in Column A and a list of the filter condition that corresponds to that ID in column B.

What I want to do is have a script that first clears the sheets I am copying to, then filters my master sheet using the condition in Column B on sheet2 then pastes that information into sheet1 of the spreadsheet ID located in Column A of sheet2.

I have pasted a link to some test sheets that will hopefully give a better idea of what I am trying to achieve.

Data Saucehttps://docs.google.com/spreadsheets/d/14jgvclYI389opkPGmNYstaTJ2DojIyf6Nl2jXbQH5_s/edit?usp=sharing

Result Data 1https://docs.google.com/spreadsheets/d/1tY6CZFQh68afX_O4E1csmGk40Fiyuy_WOJbzGW0cjJE/edit?usp=sharing

Result Data 2https://docs.google.com/spreadsheets/d/1UzwVsnntUNShBkjnII2Tt34Datl3UUy8x9RoSE5AGdw/edit?usp=sharing

Code V2,

So I think I am nearly there with this code, the Filter does not apply and its not picking up the id from the cell, but I can feel I am close.

Just wish I could find that final bit to get it right.

function get_data(){  var s1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("MasterData");  var s3 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("URL's")    var range = s1.getRange(2, 1, s1.getLastRow(), s1.getLastColumn())  var filter = range.getFilter() || range.createFilter();  var foo_index = 1; // column A  var data = []  for (var j = 0;j<s3.getLastRow()+1; j++){   var filterName = s3.getRange(j+1, 2).getValue()   var filterValue = SpreadsheetApp.newFilterCriteria().whenTextEqualTo(filterName).build()   var id = s3.getRange(j+1,1).getValue()   for (i = 1; i < s1.getLastRow(); i++){    if(!s1.isRowHiddenByFilter(i)) {      var row_data = s1.getRange(i+1, 1, 1, s1.getLastColumn()).getValues()      data.push(row_data[0])      var s2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(id)      var clear = s2.getRange(2,1,s2.getLastRow(),s2.getLastColumn()).clear({contentsOnly: true})      var paste = s2.getRange(s2.getLastRow()+1,1,data.length,4).setValues(data)    }    }  }}

Viewing all articles
Browse latest Browse all 9626

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>