Comparing two columns, same row, for first value that doesn't match

45
May 18, 2019, at 1:20 PM

I have two sheets, one is a mirror sheet, "Sheet2," that I use to store the values of the other sheet, "Sheet1." My goal is to have a function compare the two sheets for differences. The best way i could think of was by comparing column A from Sheet1 to column A from Sheet2. I found a few functions that compared 2 columns but it did it looking for values from one column and finding it in the other column. Or by returning all the values in those cells that had a matching value, regardless of what row it was in. But I don't want the values in the cells, necessarily. I want to find the first row where the two columns stop matching. I'm fairly new to Javascript so I still can't comprehend the whole for (var j = 0; j < range.length; j++) stuff.

But I'm sure I will need to know how to use it for this function I need. Here's what I tried using but instead of giving me row ranges, it gave me an array of values that were the same, if I changed it to if(lookup[i][0]!==range[j][0]){ it gave me all the possible combinations that weren't matching. This is from stackoverflow.com/questions/42044903

function findDifference() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s=ss.getSheetByName("Sheet1")
  var lr=s.getLastRow()
  var lookup = s.getRange(2,1,lr-1,2).getValues();
  var s1=ss.getSheetByName("Sheet2") 
  var lr1=s1.getLastRow()
  var range = s1.getRange(2,1,lr1-1,2).getValues();
  var lookupRange = [];
  for (var i = 0; i < lookup.length; i++) {
     for (var j = 0; j < range.length; j++) {
     var  test=lookup[i][0]
         if(lookup[i][0]!==range[j][0]){
           lookupRange.push([range[j][0],range[j][1],lookup[i][0],lookup[i][1],]);
     }}}
   s1.getRange(10,1,lookupRange.length,4).setValues(lookupRange); 
}

I feel like there's a very similar function for what I'm trying to do that already exists, but I can't seem to find it or come up with how it would work because I'm new and don't know all the tricks. Something like:

var ss = SpreadsheetApp.getActiveSpreadsheet();
  var s1=ss.getSheetByName("Sheet1")
  var s2=ss.getSheetByName("Sheet2")
var ColumnA1 = s1.getRange('A:A').getValues()
var ColumnA2 = s2.getRange('A:A').getValues()
var Row = Function()
///Some function I can't think of using where
if(ColumnA1 + Row !== ColumnA2 + Row){
???.getRow()
}
READ ALSO
Uncaught ReferenceError: d3 is not defined in WordPress Visual Composer

Uncaught ReferenceError: d3 is not defined in WordPress Visual Composer

I want to edit some images which can only be done in WPBakery Page BuilderSo, when I try to edit the page with it, the frontend editor (page builder) doesn't loads

59
Is a semicolon required before a function closure in javascript?

Is a semicolon required before a function closure in javascript?

I'm wondering if this is a compiler bug, or this is the way it's supposed to be

51
Custom object lab for my javascript class not running properly

Custom object lab for my javascript class not running properly

I'm working on a lab for my Javascript class and it is a lab dedicated to custom objects and constructor functionsobject

45
How do I publish video that is dynamically loaded?

How do I publish video that is dynamically loaded?

OpenTok has a demo that publishes a video from a fileI want to publish a video that is dynamically loaded from Firebase based on their basic demo but the publisher is not displaying the video I pull from firestore and I believe it has to do with when I call the publish...

45