'Google Sheets: Copy and Paste from one sheet to another based on checkbox
I posted a question a few weeks ago stating I'm a sort of a newbie at all of this and I am trying to learn.
I am trying to write some script for a spreadsheet I am trying to make for work, just to make things a bit easier in the long term.
Basically what I have is a "Setup" page named FF Setup for my file where I select all of the items, I would like to have shown in the final document named FF Master. I then have another sheet with all of the info/other formulas I would like to copy over to my final document based on what I select on the setup sheet named FF All
FF Setup
FF Master
FF All
I have some code written that I have been working on but for some reason, it stops at the search for checkboxes on my setup page in column B. It will log and show all of the lines in the sheet but stops after that and I can not figure it out for the life of me.
Here is the link to my file and also added the code below
function copyAndPaste(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ffSetup = ss.getSheetByName("FF Setup");
var ffAll = ss.getSheetByName("FF All");
var ffMaster = ss.getSheetByName("FF Master");
var allData = ffAll.getDataRange().getValues();
var ffData = ffSetup.getDataRange().getValues();
for( var i = 0; i < ffData.length; i++ ) {
Logger.log( "row:" + ( i + 1 ) );
if( ffData[ i ][ 1 ] == "TRUE" ) {
Logger.log( "foundtrue" );
var search = ffSetup.getRange( i + 1, 3 ).getValue();
for( var j = 0; j < allData.length; j++ ) {
if( masterData[ j ][ 1 ] == search ) {
var nextRow = ffMaster.getLastRow() + 1;
var getCopyRange = ffAll.getRage( 'A' + j + ':C' + j );
getCopyRange.copyTo( ffMaster.getRage( nextRow, 1 ) );
}
}
}
}
}
I do eventually also want each line to show under its relative category and header as you see on the "FF All" sheet. But, I haven't even attempted that part yet cause I am stuck here. So if anyone wants to give me some tips for that as well then I would appreciate it haha
I don't even know if this is the best way to even go about doing what I am trying to accomplish so if there are suggestions please also send them my way!
Solution 1:[1]
Got it all figured out! thanks for the help!...even though it was a stupid mistake lol
My code ended up being:
function copyAndPaste() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ffSetup = ss.getSheetByName("FF Setup");
var ffAll = ss.getSheetByName("FF All");
var ffMaster = ss.getSheetByName("FF Master");
var allData = ffAll.getDataRange().getValues();
var ffData = ffSetup.getDataRange().getValues();
var masterData = ffMaster.getDataRange().getValues();
for(var i = 0; i<ffData.length;i++){
if(ffSetup.getRange('B'+(i+1)).isChecked() === true){
var search = ffSetup.getRange(i+1,3).getValue()
for(var j = 0; j<allData.length;j++){
if(allData[j][1] == search) {
var nextRow = ffMaster.getLastRow() +1;
var getCopyRange = ffAll.getRange('A'+(j+1)+':N'+(j+1));
getCopyRange.copyTo(ffMaster.getRange(nextRow,1));
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Chantie1126 |