I have 2 columns, A contains units & B data. I want to delete entire rows from A & B where text in B does not contain '-'.
I have other data in the other columns in the sheet, so this should only apply to A & B.
I normally manually filter and delete these rows.
Following the script in this question, when I used exactly this but with "| My Text Here" replace with "-", it worked, but a lot of the data that should be there were also deleted. So when I should have had 300 rows of data left, I only had 124 after running the script. How to delete rows that do not containing specific text within A column using Google Sheets App?
function deleteFunction(){
//declarations
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName('Sheet1');
var dataRange = sheet.getDataRange();
var values = dataRange.getValues();
for(var i=values.length-1;i>0;i--){
var myValue=values[i][0];
Logger.log(i);
if( myValue.indexOf("-")==-1){
Logger.log(myValue);
sheet.deleteRow(i+1);
}
}
}
When I change the dataRange to just getRange('A1:B');
the function keeps going for ages without results.
I changed it to .getRange(1, 2, dataRange.getLastRow(), dataRange.getLastColumn());
and that deletes ALL the data in the range.
Basically, at this point I'm confused, I keep changing the ranges to try to see results.
I'm a newbie to this so I'm not sure where I go wrong.