Home > Blockchain >  Need to find duplicate data in another sheet and delete row
Need to find duplicate data in another sheet and delete row

Time:08-16

Need some help. I need Script to check data in B3 Sheet 2 and find Data in colum A in Sheet 1 and Delete row duplicate data Thank you.

Sample

https://i.stack.imgur.com/3sT3X.jpg

https://i.stack.imgur.com/zTRtg.jpg

CodePudding user response:

I believe your goal is as follows.

  • From I need Script to check data in B3 Sheet 2 and find Data in colum A in Sheet 1 and Delete row duplicate data, you want to delete rows of "Sheet1" by searching the values of column "A" using a value of "B3" of "Sheet2".
  • You want to achieve this using Google Apps Script.

In this case, how about the following sample script?

Sample script 1:

In this sample, TextFinder is used. If the number of deleting rows is small, this script might be useful. Please copy and paste the following script to the script editor of Spreadsheet. And, please confirm your sheet names again. And, please run sample1.

function sample1() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet1 = ss.getSheetByName("Sheet1");
  const sheet2 = ss.getSheetByName("Sheet2");
  const search = sheet2.getRange("B3").getDisplayValue();
  sheet1.getRange("A2:A"   sheet1.getLastRow()).createTextFinder(search).findAll().reverse().forEach(r => sheet1.deleteRow(r.getRow()));
}

Sample script 2:

In this sample, filter and setValues are used. If the number of deleting rows is large, this script might be useful. Please copy and paste the following script to the script editor of Spreadsheet. And, please confirm your sheet names again. And, please run sample2.

function sample2() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet1 = ss.getSheetByName("Sheet1");
  const sheet2 = ss.getSheetByName("Sheet2");
  const search = sheet2.getRange("B3").getValue();
  const range = sheet1.getDataRange();
  const values = range.getValues().filter(([a]) => a != search);
  range.clearContent().offset(0, 0, values.length, values[0].length).setValues(values);
}

Note:

  • When this script is run, I think that your showing goal will be achieved.
  • But, if your actual Spreadsheet is different from your question and/or if your question has hidden requests, this script might not be able to be used. Please be careful about this.

References:

  • Related