Overclock.net banner

Multiple Issues with Google Sheets Scripts (JavaScript)

1559 Views 1 Reply 2 Participants Last post by  huzzug
Hello all, NEEDLES TO SAY, I am very new to this, but trying my hardest to figure all this out. I have a script right now which actively removes all empty rows from an entire workbook. But I'm hoping someone can assist is narrowing this down to a single sheet within that workbook.
Code:
function removeEmptyRows() {
    SpreadsheetApp.getActive()
        .getSheets()
        .forEach(function (s) {
            c = 0;
            s.getRange(1, 1, s.getMaxRows(), s.getMaxColumns())
                .getValues()
                .forEach(function (r, j) {
                    if (r.toString()
                        .replace(/,/g, "")
                        .length == 0) {
                        s.deleteRow((j += 1) - c)
                        c += 1;
                    }
                })
        })
}
Ideally I would like for this to remove only blank rows on one sheet within my workbook called 'Racing Results'. The reason I'm need this, is due to how the spreadsheet is setup and having multiple rows merged together. So when I copy these results over to a different sheet, there are gaps between them and I'd like them removed. Here is the script I'm using to copy the data to another sheet.
Code:
function Copy() {

 var sss = SpreadsheetApp.openById('18cl69Id4saI455wk__-PhvfxXZa7iWlQpoiRKqBz6bU');
 var ss = sss.getSheetByName('Score Card');
 var range = ss.getRange('A32:E36');
 var data = range.getValues();
 var tss = SpreadsheetApp.openById('18cl69Id4saI455wk__-PhvfxXZa7iWlQpoiRKqBz6bU');
 var ts = tss.getSheetByName('Race Results');

 ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);

}
If not to throw one final monkey wrench into this colossal mess, I have been attempting to copy two different cell ranges within the same script and I feel like this isn't possible because only the latter one gets copied and the initial one is discarded. Here is the other copy script I am using which runs before the one above this.
Code:
 function Copy() {
  
var sss = SpreadsheetApp.openById('18cl69Id4saI455wk__-PhvfxXZa7iWlQpoiRKqBz6bU');
 var ss = sss.getSheetByName('Score Card');
 var range = ss.getRange('A1:A1');
 var data = range.getValues();
 var tss = SpreadsheetApp.openById('18cl69Id4saI455wk__-PhvfxXZa7iWlQpoiRKqBz6bU');
 var ts = tss.getSheetByName('Race Results');

 ts.getRange(ts.getLastRow()+1, 1, data.length, data[0].length).setValues(data);
  
}


In a perfect world, what I'm trying to get setup is the following. Above is a screenshot of the scorecard we are using. I am wanting to copy the Current Date (A1) to the 'Racing Results' sheet, then I want to copy the final score with the team names (A32:E36) and move them to the 'Racing Results' sheet right under it. Once that has been done, I want to remove the empty rows between the results because as of right now this is how it looks when copying over. (see image below)



Thanks in advance to anyone who is able to assist with any of this in any way shape or form.
1 - 2 of 2 Posts

· What should be here ?
Joined
·
20,056 Posts
Sorry for necroeing this thread and I'm aware you might have found out how to do what you wanted to do, but can you tell us how the data is beign populated? Also, are there any even triggers that runs the scripts? Also, have your tried to use offset to find and populate data to the next empty row?

And if you did find out how to do it, can you share how you were able to?
 
1 - 2 of 2 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top