How to highlight cell if value duplicate in same column for google spreadsheet?

前端 未结 6 693
囚心锁ツ
囚心锁ツ 2020-12-07 06:48

I am looking for formula for google spreadsheet highlight cell if value duplicate in same column

can anyone please assist me for this query?

6条回答
  •  渐次进展
    2020-12-07 07:32

    I tried all the options and none worked.

    Only google app scripts helped me.

    source : https://ctrlq.org/code/19649-find-duplicate-rows-in-google-sheets

    At the top of your document

    1.- go to tools > script editor

    2.- set the name of your script

    3.- paste this code :

    function findDuplicates() {
      // List the columns you want to check by number (A = 1)
      var CHECK_COLUMNS = [1];
    
      // Get the active sheet and info about it
      var sourceSheet = SpreadsheetApp.getActiveSheet();
      var numRows = sourceSheet.getLastRow();
      var numCols = sourceSheet.getLastColumn();
    
      // Create the temporary working sheet
      var ss = SpreadsheetApp.getActiveSpreadsheet();
      var newSheet = ss.insertSheet("FindDupes");
    
      // Copy the desired rows to the FindDupes sheet
      for (var i = 0; i < CHECK_COLUMNS.length; i++) {
        var sourceRange = sourceSheet.getRange(1,CHECK_COLUMNS[i],numRows);
        var nextCol = newSheet.getLastColumn() + 1;
        sourceRange.copyTo(newSheet.getRange(1,nextCol,numRows));
      }
    
      // Find duplicates in the FindDupes sheet and color them in the main sheet
      var dupes = false;
      var data = newSheet.getDataRange().getValues();
      for (i = 1; i < data.length - 1; i++) {
        for (j = i+1; j < data.length; j++) {
          if  (data[i].join() == data[j].join()) {
            dupes = true;
            sourceSheet.getRange(i+1,1,1,numCols).setBackground("red");
            sourceSheet.getRange(j+1,1,1,numCols).setBackground("red");
          }
        }
      }
    
      // Remove the FindDupes temporary sheet
      ss.deleteSheet(newSheet);
    
      // Alert the user with the results
      if (dupes) {
        Browser.msgBox("Possible duplicate(s) found and colored red.");
      } else {
        Browser.msgBox("No duplicates found.");
      }
    };
    

    4.- save and run

    In less than 3 seconds, my duplicate row was colored. Just copy-past the script.

    If you don't know about google apps scripts , this links could be help you:

    https://zapier.com/learn/google-sheets/google-apps-script-tutorial/

    https://developers.google.com/apps-script/overview

    I hope this helps.

提交回复
热议问题