Skip to content

checkMatchingValues #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions functions/checkMatchingValues
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @a1ex.garofalo WorkspaceDevs https://developers.google.com/apps-script/guides/sheets/functions#optimization
/**
* Checks if values in one column on a certain sheet match values in another column in a different sheet
*/
function checkMatchingValues(sourceSheetName, sourceColumn, targetSheetName, targetColumn) {
var sourceSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(sourceSheetName);
var targetSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(targetSheetName);

var sourceValues = sourceSheet.getRange(sourceColumn).getValues();
var targetValues = targetSheet.getRange(targetColumn).getValues();

var sourceValuesFlat = sourceValues.flat().filter(String);
var targetValuesFlat = targetValues.flat().filter(String);

for (var i = 0; i < sourceValuesFlat.length; i++) {
if (targetValuesFlat.indexOf(sourceValuesFlat[i]) === -1) {
return false;
}
}

return true;
}