Count a list of cells with the same background color

后端 未结 5 1283
时光取名叫无心
时光取名叫无心 2020-12-19 01:22

Each cell contains some text and a background color. So I have some cells that are blue and some that are red. What function do I use to count the number of red cells?

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 01:59

    The worksheet formula, =CELL("color",D3) returns 1 if the cell is formatted with color for negative values (else returns 0).

    You can solve this with a bit of VBA. Insert this into a VBA code module:

    Function CellColor(xlRange As Excel.Range)
        CellColor = xlRange.Cells(1, 1).Interior.ColorIndex
    End Function
    

    Then use the function =CellColor(D3) to display the .ColorIndex of D3

提交回复
热议问题