Skip to content

Instantly share code, notes, and snippets.

@dorward
Created May 21, 2021 06:55
Show Gist options
  • Save dorward/a9863d151a0ace3d5267dcba908fade5 to your computer and use it in GitHub Desktop.
Save dorward/a9863d151a0ace3d5267dcba908fade5 to your computer and use it in GitHub Desktop.
Replaces / with \ in Google Sheets
function onOpen() {
const ui = SpreadsheetApp.getUi();
ui.createMenu('Extras')
.addItem('Replace / with \\ in selection', 'replaceSlashes')
.addToUi();
}
function replaceSlashes() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const range = SpreadsheetApp.getActive().getActiveRange();
const numRows = range.getNumRows();
const numCols = range.getNumColumns();
for (let i = 1; i <= numCols; i++) {
for (let j = 1; j <= numRows; j++) {
const cell = range.getCell(j, i)
cell.setValue(cell.getValue().replace(/\//g, "\\"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment