Last active
May 18, 2022 23:34
Conditional Formatting in Google App Script based on cell value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If the current cell is more than the previous cell, set it as lime green | |
function onEdit(e) { | |
var ss = SpreadsheetApp.getActive(); | |
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); | |
var name = sheet.getName(); | |
var range = sheet.getRange("A:J"); | |
var values = range.getValues(); | |
var cell = sheet.getActiveCell(); | |
var value = cell.getValue(); | |
var currentRow = cell.getRow(); | |
var currentColumn = cell.getColumn(); | |
var previousPosition = currentColumn -1; | |
var previousPositionValue = sheet.getRange(currentRow, previousPosition).getValue(); | |
//Loop through the range and if the active cell is greater than the previous cell, set to lime green | |
for(i in range) { | |
if(value > previousPositionValue){ | |
cell.setBackground('#00ff00'); | |
} else { | |
cell.setBackground('white'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment