I can Trim my dada with the script below
But is there a way Clean data in Google using a Google Script similar to Clean in VBA?
i.e. Remove all non-printing characters
I am unable to find-replace on data copied and pasted into GS from another source
Thanks
function trimSpacesSHT(shtName) {
var sheet = SpreadsheetApp.getActive().getSheetByName(shtName);
var activeRange = sheet.getDataRange();
// Read Height and Width only once
var maxHeight = activeRange.getHeight();
var maxWidth = activeRange.getWidth();
// Read all values and formulas at once
var rangeValues = activeRange.getValues();
// iterate through all cells in the selected range
for (var cellRow = 0; cellRow < maxHeight; cellRow++) {
for (var cellColumn = 0; cellColumn < maxWidth; cellColumn++) {
rangeValues[cellRow][cellColumn] = rangeValues[cellRow][cellColumn].toString().trim().replace(/\s(?=\s)/g,'');
}
}
// Write back all values at once
activeRange.setValues(rangeValues);
}