Google App Script - Conditional Formatting Based on Another Cell

后端 未结 2 1237
没有蜡笔的小新
没有蜡笔的小新 2021-01-26 09:29

I am trying to figure out how to use conditional formatting via script on a google spreadsheet similar to what you can do with the conditional formatting feature.

I have

2条回答
  •  失恋的感觉
    2021-01-26 10:22

    Let's assume that Country is placed at (1,1) and State is placed at (1,2) where (i,j) indicates the ith row and jth column on the Spreadsheet. Google Spreadsheets is 1-indexed meaning indices start at 1.

    var activeSheet = SpreadsheetApp.getActiveSheet();
    
    for (var a = 2; a < activeSheet.getLastRow(); a++) {
       if (String(activeSheet.getRange(a,1).getCell(1,1)) === "United States") { 
           if (String(activeSheet.getRange(a,2).getCell(1,1)) === null) { 
              activeSheet.getRange(a, 2, 1, 1).setBackgroundColor('red'); 
           } 
       } 
    }
    

提交回复
热议问题