Google Sheets – Fixing Parameter Mismatch in setValues Method

google sheetsgoogle-apps-script

With the following function:

function updateCells() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var spreadsheetSummary = ss.getSheetByName('Summary');
  const range = spreadsheetSummary.getDataRange()
  const values = range.getDisplayValues()
  const transposeCheck = values[0].map((_, iCol) => values.map(row => row[iCol]).some(cell => cell))
  var countBoolean = transposeCheck.filter(Boolean).length
  var spreadsheetCommunityGroups = ss.getSheetByName('Community Groups');
  var cellValueCommunityGroups = spreadsheetCommunityGroups.getRange('A12').getValue();
  var summaryCommunityGroups = 'B'+countBoolean++
  spreadsheetSummary.getRange(summaryCommunityGroups).setValues(cellValueCommunityGroups);
}

I receive error

Exception: The parameters (number) don't match the method signature
for SpreadsheetApp.Range.setValues.

Best Answer

Please try this:

function updateCells() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var spreadsheetSummary = ss.getSheetByName('Summary');
  const range = spreadsheetSummary.getDataRange()
  const values = range.getDisplayValues()
  const transposeCheck = values[0].map((_, iCol) => values.map(row => row[iCol]).some(cell => cell))
  var countBoolean = transposeCheck.filter(Boolean).length + 1
  var spreadsheetCommunityGroups = ss.getSheetByName('Community Groups');
  var cellValueCommunityGroups = spreadsheetCommunityGroups.getRange('A12').getValue();
  var summaryCommunityGroups = 'B'+countBoolean
  spreadsheetSummary.getRange(summaryCommunityGroups).setValue(cellValueCommunityGroups);
}