Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9624

Google Sheet Script - if cell value is less than zero

$
0
0

This script doesn't work, and I just can't figure out why. Cell D7 contains the absolute value of cell E7. If the value in cell E7 is negative, then I want to fake it so that cell D7 appears negative, by changing the cell format.

Something in the if statement isn't working. This code runs, but for some reason the 'if E7 < 0' logic always fails, and then the action defaults to the 'else' statement. Does anyone see what I'm missing? Thank you!

function formatpercentchange() {

var spreadsheet = SpreadsheetApp.getActive();

if(spreadsheet.getRange('E7').value < 0)   {
    spreadsheet.getRange('D7').activate();
    spreadsheet.getActiveRangeList().setNumberFormat('[red]"▼ "-0.0%');   }

else   {   //var spreadsheet = SpreadsheetApp.getActive(); 
    spreadsheet.getRange('d7').activate();   
    spreadsheet.getActiveRangeList().setNumberFormat('"▲ "0.0%');   } }

Viewing all articles
Browse latest Browse all 9624

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>