Advertisement
voidpointer

Untitled

Jul 7th, 2011
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function onEdit()
  2. {
  3.   highlightActualCells();
  4. }
  5.  
  6. function onOpen()
  7. {
  8.   highlightActualCells();
  9. }
  10.  
  11. function highlightActualCells()
  12. {
  13.   var ss = SpreadsheetApp.getActiveSpreadsheet();
  14.   var actual = ss.getRangeByName( 'actual_highlight_range' );
  15.   var category = ss.getRangeByName( 'category_highlight_range' );
  16.  
  17.   var bgColors = actual.getBackgroundColors();
  18.   var actualVals = actual.getValues();
  19.   var categoryVals = category.getValues();
  20.  
  21.   var newBgColors = bgColors;
  22.   var white = 'white';
  23.   var yellow = '#ffff88';
  24.   var black = '#000000';
  25.  
  26.   for( var r = 0; r < bgColors.length; ++r )
  27.   {
  28.     var color = bgColors[r][0];
  29.     if( color != black )
  30.     {
  31.       var actualVal = actualVals[r][0];
  32.       var categoryVal = categoryVals[r][0];
  33.      
  34.       if( categoryVal > 0 && !actualVal )
  35.       {
  36.         newBgColors[r][0] = yellow;
  37.       }
  38.       else
  39.       {
  40.         newBgColors[r][0] = white;
  41.       }
  42.     }
  43.   }
  44.  
  45.   actual.setBackgroundColors( newBgColors );
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement