0

I wrote a Google Sheets Apps Script to function as a data entry form for my team to use. The script works great, but I'm looking for a way to improve it. I'd like to be able to skip the first column in the sheet where the entry line gets dropped into ("Archive" sheet). So the data would get dropped starting in Column 2 instead of Column 1. How do I make the AppendRow offset over by one column in this way?

function Entry() {  
  var ui = SpreadsheetApp.getUi();  
  var result = ui.alert(  
    'Please only log this data when you have finished the brew',
    ui.ButtonSet.YES_NO);  
    if(result == ui.Button.YES) {  
    var ss = SpreadsheetApp.getActive();  
      var ent = ss.getSheetByName("Form Entry");  
      var prev = ss.getSheetByName("Archive");  
      var copy = ent.getRange('I3:AZ3');  
      prev.appendRow(copy.getValues()[0]);  
      var rangelist = ent.getRangeList(['C4','C6:C13','B18:D27','B29']).clearContent();  
      return  
      
  } else {  
    return;  
  }  
    }

1 Answer 1

0

Construct an array that starts with an extra blank value, and get the values in copy using spread syntax, like this:

      prev.appendRow([null, ...copy.getValues().flat()]);

See Spread syntax.

In the event you have values or formulas in other columns in the prev sheet, and always want to write after the last value in column B regardless of what is in the other columns, use the appendRows_() utility function, like this:

      appendRows_(prev, copy.getValues(), 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.