I wanted to make a script that searches 9 specified sheets in the whole spreadsheet for the value of four cells next to each other, and when it finds it, it deletes the value from only the last cell it found.
Example:
Input part:
data1 | data2 | data3 | data4 |
-------------------------------
ABC | 123 | XYZ | MNO |
-------------------------------
[Search and destroy button]
The four data values would be searched in the sheets that look like this where is should be found and deleted:
A B C D E F G H I
1 |data1 | data2 |data3 | data4 | |data1 | data2 |data3 | data4 |
2 |------|-------|------|-------|---|------|-------|------|-------|
3 | gfd | nbv | hgf | hjg | | sdg | uzt | saf | hdd |
4 |------|-------|------|-------|---|------|-------|------|-------|
5 | ztr | mvb | ABC | jgf | | uzt | XYZ | XYZ | ABC |
6 |------|-------|------|-------|---|------|-------|------|-------|
7 | ioj | lkj | gfd | jgf | | ABC | 123 | XYZ | MNO |
8 |------|-------|------|-------|---|------|-------|------|-------|
9 | mnb | ztd | jgf | gfd | | nfs | tez | hfd | xyv |
10 |------|-------|------|-------|---|------|-------|------|-------|
In this case it would need to find the data thats from F7 to I7 and delete the value from I7.
Is this possible? Its a little more advanced then what im capable of figuring out unfortunately.
Edit: This is what i was able to come up with that works as i wanted it to. I have to specify the Sheet names, but its not a problem i can get that from the data anyway.
function SaF() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var ss = sh.getActiveSheet();
var cell = ss.getRange('A1:D1');
var value = cell.getValues();
var shname = ss.getRange('Q9').getValue();
var sheets = sh.getSheetByName(shname)
var activeR = cell.getRow()-1;
var activeC = cell.getColumn()-1;
var data = sheets.getRange("A1:BS87").getValues()
var step = 0
for(var r=activeR;r<data.length;++r){
for(var c=activeC;c<data[0].length;++c){
step++
Logger.log(step+' -- '+value[0]+' = '+data[r][c]);
if(data[r][c]==''||step==1){ continue };
if(value[0][0]==data[r][c] && value[0][1]==data[r][c+1] && value[0][2]==data[r][c+2] && value[0][3]==data[r][c+3]){
sheets.getRange(r+1,c+4).clearContent();
return;
}
}
}
}
Its probably not very clean, and could be made better like:
- I cant specify a source thats not from A1, i suspect this is cause of the way it looks up rows and columns, but dont have the knowhow to change it.
ABC | 123 | XYZ | MNOare located in other cells sayA3:D3or in the mentioned cells only? - user13338210textFinder- Cooper