Skip to content

Instantly share code, notes, and snippets.

@palumbo
Created August 27, 2022 19:45
Show Gist options
  • Save palumbo/c449ea530ef4eec904628b7257697364 to your computer and use it in GitHub Desktop.
Save palumbo/c449ea530ef4eec904628b7257697364 to your computer and use it in GitHub Desktop.
Checking values against an array to prevent data duplication
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var lastRow = sheet.getLastRow()
var employees = [];
for ( var i = 0; i < lastRow; i++) {
let value = sheet.getRange(i+1,1).getValue();
employees.push(value);
};
Logger.log(employees);
}
function myFunction() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var nameArray = ["Eddie", "Jaime", "Katie", 42];
var inputFromUser = Browser.inputBox('Please enter a value');
Logger.log(inputFromUser);
let checkCell = sheet.getRange("A1");
if ( nameArray.indexOf(inputFromUser) >= 0) {
checkCell.setValue("That value is in the array");
} else {
checkCell.setValue("That value is NOT in the array");
checkCell.setBackground("red");
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment