Highlight Row if Value in Column is above 0 - Google Spreadsheet
Asked Answered
M

3

7

I am trying to get a Google spreadsheet to automatically highlight all rows in a spreadsheet where the value in a particular column is above 0. I have looked for a few solutions but haven't got it to work.

I have got various metrics in the columns, so say I want to highlight all rows, in which column "I" has a value of more than zero.

Can someone help me with this?

Mauve answered 28/3, 2013 at 18:4 Comment(0)
S
2

The only solution I'm aware of would be to write a script.

Link: Google Apps Scripts

The following is not pretty, but it works:

function myFunction() {
  var I_INDEX = 1;
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Highlight rows");
  var dataRange = sheet.getDataRange();
  var dataValues = dataRange.getValues();
  for (var i=1; i<=dataRange.getNumRows(); i++) {
    var row = sheet.getRange(i, 1, 1, 2);
    if (dataValues[i-1][I_INDEX] > 0) {
      row.setBackground("red");
    }
  }
}

See example, use "Tools" --> "Script Editor..." to view/run the script.

Spiculate answered 30/3, 2013 at 17:1 Comment(3)
HI, Thanks for the response, Where in this script can I specify which column to run this script against. i.e column J...Mauve
I figured it out! Thank you very much! Legend!Mauve
Thanks! If this answered your question, please "accept" the answer - stackoverflow.com/faq#howtoaskSpiculate
M
8

On the conditional formatting page choose "Custom formula is" from the list of options available and then in the text field type:

=$I:$I>0

Select your formatting options and then in the range field type the range. For example:

A2:Z100
Mitchmitchael answered 9/2, 2015 at 10:52 Comment(1)
This is a simpler answer.Chery
C
3

Because only to be applied to a single column there is a simpler version (that I have complicated so that text is not highlighted):

Clear formatting, select ColumnI and Format, Conditional formatting..., Format cells if... Custom formula is and:

=and(isnumber(I1),I1>0)

with fill of choice and Done.

If to format not just the relevant cell but the entire row then change the Apply to Range (say to A1:Z1000) and add anchors ($s) as below:

=and(isnumber($I1),$I1>0)
Coact answered 6/6, 2017 at 0:23 Comment(0)
S
2

The only solution I'm aware of would be to write a script.

Link: Google Apps Scripts

The following is not pretty, but it works:

function myFunction() {
  var I_INDEX = 1;
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Highlight rows");
  var dataRange = sheet.getDataRange();
  var dataValues = dataRange.getValues();
  for (var i=1; i<=dataRange.getNumRows(); i++) {
    var row = sheet.getRange(i, 1, 1, 2);
    if (dataValues[i-1][I_INDEX] > 0) {
      row.setBackground("red");
    }
  }
}

See example, use "Tools" --> "Script Editor..." to view/run the script.

Spiculate answered 30/3, 2013 at 17:1 Comment(3)
HI, Thanks for the response, Where in this script can I specify which column to run this script against. i.e column J...Mauve
I figured it out! Thank you very much! Legend!Mauve
Thanks! If this answered your question, please "accept" the answer - stackoverflow.com/faq#howtoaskSpiculate

© 2022 - 2024 — McMap. All rights reserved.