Skip to content
Advertisement

highlighting maximum values in a specific column using Google App Script

I`m trying to write a script that can find the maximum value in a specific column (proportion column in the given dataset) and highlight the cell accordingly.

Below is where I am at so far

JavaScript

And below is the dataset I am using for this enter image description here

so if the above code properly worked, it should`ve highlighted the first row in the last column which is 0.27% as this is the maximum value found in this column.

For the below part, I`ve also tried using for loop. But no luck there

Can someone please advise on how i can get this work?

JavaScript

Advertisement

Answer

Answer 1

You can highlight the maximum value in a specific column using Conditional formatting.

Steps

  1. Go to Format > Conditional formatting
  2. Select the range to apply the format
  3. Select Custom formula is in Format cells if
  4. Apply =(G:G)=MAX(G:G) to select the cell with highest value

Answer 2

You can get and highlight the highest value in a simple way:

JavaScript

Explanation

  1. var merged = [].concat.apply([], values) transforms an array of arrays into an array of integers.
  2. var max = Math.max.apply(Math,merged) gets the highest value of the range
  3. var maxid = merged.indexOf(max) gets the index of the highest value
  4. range.getCell(maxid+1,1).setBackgroundRGB(0,255,0) change the background of the desired cell. Keep in mind that the index of the array starts from 0 and the index from the cell from 1, so you have to sum 1 to the index. Furthermore, in RGB, green is equal to zero red, full green, zero blue.
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement