0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google App Scriptでセルの値を比較する

Posted at

function myFunction() {

var ss1 = SpreadsheetApp.getActiveSpreadsheet();
var sheet1 = ss1.getSheetByName("s1");
var data1 = sheet1.getRange(1, 1, sheet1.getLastRow(),1).getValues();
var val1=data1[0].toString();

var sheet1w = ss1.getSheetByName("s1");

var ss2 = SpreadsheetApp.getActiveSpreadsheet();
var sheet2 = ss2.getSheetByName("s2");
var data2 = sheet2.getRange(4, 2, sheet2.getLastRow()-3,1).getValues();
var val2=data2[0].toString();

var sheet2w = ss1.getSheetByName("s2");

/*
if (val1==val2){
console.log("same");
}else{
console.log("NG");
}
*/

var matched_flg ;

for (var i = 0; i < data1.length; i++) {

matched_flg=false;

  for (var ii = 0; ii < data2.length; ii++) {
            
    //console.log(data2[i]);
    
    if (data1[i].toString()==data2[ii].toString()){
      
      console.log("データ1:" + data1[i] + " データ2:" + data2[ii] + " " + "☆same") ;
      sheet1w.getRange(i+1, 4).setValue(true);
      sheet2w.getRange(i+4, 4).setValue(true);
      matched_flg=true;
      break;
    
    } else{
      
      console.log("データ1:" + data1[i] + " データ2:" + data2[ii] + " " + "☆different") ;          
      
    }         
  }

if (matched_flg==true) {
  
  sheet2w.getRange(i+4, 4).setValue(true);     
        
}



//console.log(data1[i]);

}

/*
console.log(val1==val2);
console.log(val1===val2);
console.log(data1[0].toString()==data2[0].toString());
console.log(data1[0]===data2[0]);
*/

}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?