Reputation: 15
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.sstatic.net/3sT3X.jpg
https://i.sstatic.net/zTRtg.jpg
Upvotes: 1
Views: 68
Reputation: 201573
I believe your goal is as follows.
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".In this case, how about the following sample script?
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()));
}
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);
}
Upvotes: 0