var ui = SpreadsheetApp.getUi();
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Automation')
.addItem('Delete Enters', 'deleteEnters')
.addToUi();
}
function deleteEnters() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
if (!sheet){
ui.alert("There is no sheet with config!");
}
var lastColumn = sheet.getLastColumn();
var lastRow = sheet.getLastRow();
for (i = 1; i <= lastColumn; i++) {
for (j = 1; j <= lastRow; j++) {
var tempText = sheet.getRange(j,i).getValue();
tempText = tempText.replace(/\n/g,"");
sheet.getRange(j, i).setValue(tempText);
}
}
}
Hi, I made for you this simple code. Thanks to this, you can choose on current sheet option Automation > Delete Enters and script automatically replace \n for ""
You can change this line:
tempText = tempText.replace(/\n/g,"");
for your own regex, if you want replace enters per something else.
1While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill – 2015-06-27T10:25:32.960