Created
August 27, 2022 19:45
-
-
Save palumbo/c449ea530ef4eec904628b7257697364 to your computer and use it in GitHub Desktop.
Checking values against an array to prevent data duplication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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