Skip to content

Instantly share code, notes, and snippets.

@kitmenke
Created October 7, 2021 03:01
Show Gist options
  • Save kitmenke/a76213118bb9de2b4c60ec4d1f061780 to your computer and use it in GitHub Desktop.
Save kitmenke/a76213118bb9de2b4c60ec4d1f061780 to your computer and use it in GitHub Desktop.
Google Apps Script: Make Negative

A small macro to make every number in each cell negative.

function MakeNegative() {
var spreadsheet = SpreadsheetApp.getActive();
var activeRange = spreadsheet.getActiveRange();
var values = activeRange.getValues();
values.forEach(function(row, rowId) {
row.forEach(function(col, colId) {
values[rowId][colId] = Math.abs(values[rowId][colId]) * -1;
});
});
activeRange.setValues(values);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment