How to getRange for rows/columns?

558 views
Skip to first unread message

EK

unread,
May 10, 2022, 3:17:41 PM5/10/22
to Google Apps Script Community
Hi everyone, 

I created a spreadsheet form based on this tutorial: https://www.youtube.com/watch?v=v2X-fArILPA

My form has many more inputs than the example video AND I wish for the output to be displayed in rows, instead of columns. This makes it easier to copy/paste the data into other formats, like emails. 

I got almost all the scripts to work perfectly EXCEPT this line: 

 dataSheet.getRange(dataSheet.getLastColumn()+1,1,1,6).setValues(values);
  CLEAR();

I am aware that +1,1,1,6 refers to rows and columns, but I cannot seem to get it to work. 
When I add a console.log, the script runs fine, but nothing shows up in my Output sheet tab when I hit the button to "Submit."

Instead, I get this error message: 
TypeError: Cannot read property 'getRange' of null
Details: TypeError: Cannot read property 'getRange' of null

Below is the full script: 
---------------------------------------------------------

// COPY INPUTS OVER TO OUTPUT TAB (A COLLECTION OF ALL THE FORM SUBMISSIONS)
function SUBMISSIONS() {
  var ss = SpreadsheetApp.getActive();
  var formSheet = ss.getSheetByName("CRWING-INPUT")  // The name of the spreadsheet tab for the form
  var dataSheet = ss.getSheetByName("OUTPUT"); // The name of the spreadsheet tab for the collection of submissions

  var values = [[ formSheet.getRange("D8").getValue(), 
                  formSheet.getRange("D9").getValue(),
                  formSheet.getRange("D10").getValue(),
                  formSheet.getRange("D11").getValue(),
                  formSheet.getRange("D12").getValue(),

                  formSheet.getRange("C13").getValue(),
                  formSheet.getRange("C14").getValue(),
                  formSheet.getRange("C15").getValue(),

                  formSheet.getRange("E13").getValue(),
                  formSheet.getRange("E14").getValue(),
                  formSheet.getRange("E15").getValue(),
                  formSheet.getRange("E16").getValue(),

                  formSheet.getRange("D16").getValue(),
                  formSheet.getRange("D19").getValue(),

                  formSheet.getRange("B18").getValue(),

                  formSheet.getRange("E21").getValue(),
                  formSheet.getRange("E22").getValue(),
                  formSheet.getRange("E23").getValue(),
                  formSheet.getRange("E24").getValue(),
                  formSheet.getRange("E25").getValue(),
                  formSheet.getRange("E26").getValue(),
                  formSheet.getRange("E27").getValue(),

                  formSheet.getRange("F21").getValue(),
                  formSheet.getRange("F22").getValue(),
                  formSheet.getRange("F23").getValue(),
                  formSheet.getRange("F24").getValue(),
                  formSheet.getRange("F25").getValue(),
                  formSheet.getRange("F26").getValue(),
                  formSheet.getRange("F27").getValue(),
                  formSheet.getRange("F28").getValue(),
                  formSheet.getRange("F29").getValue(),
                  formSheet.getRange("F30").getValue(),
                  formSheet.getRange("F31").getValue(),
                  formSheet.getRange("F32").getValue(),

                  formSheet.getRange("D33").getValue(),
                  formSheet.getRange("D34").getValue(),
                  formSheet.getRange("D35").getValue(),
                  formSheet.getRange("D36").getValue(),

                  formSheet.getRange("E34").getValue(),

                  formSheet.getRange("D37").getValue(),

                  formSheet.getRange("E37").getValue(),

                  formSheet.getRange("C38").getValue()]];

  dataSheet.getRange(dataSheet.getLastColumn()+1).setValues(values);
  CLEAR();
}

console.log(SUBMISSIONS)




Reply all
Reply to author
Forward
0 new messages