V
V
Viktor Familyevich2017-12-06 14:56:03
Google Apps Script
Viktor Familyevich, 2017-12-06 14:56:03

How to check if there is already a value in a column using Google Scripts?

Given a variable and a column in Google Sheets with values. You need to check the values ​​in this column for matches with the variable, and if it is, return for example true. Tell me how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Samokhin, 2017-12-06
@Wintego

For example like this:

function check(sheetName, column, word) {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName(sheetName);
  var range = sheet.getRange(column);
  var values = range.getValues();

  var result = false;
  for (var i = 0; i < values.length; i++) {
    if (values[i][0] == word) {
      result = true;
      break;
    }
  }
  return result;
}

call like this
'test' is the sheet name, 'A:A' is the column, 'ask / organic' is the text we are looking for.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question