Search code examples
google-sheetsindexinghighlightconditional-formattingcountif

Counting highlighted cells in Google Sheets


Is it possible to count by highlighted cells in Google Sheets? I have conditional formatting designed to highlight the cell if it is the first time a value appears in Column A of my sheet so would it be possible to count these highlighted cells to show the number of highlighted cells?

I have come up with a fix by using another row which would in essence use the same Index formula =INDEX(COUNTIFS(B:B,B6,ROW(B:B), ">="&ROW(B6)))=1 I have for the conditional formatting but to show TRUE/FALSE values which can then be counted using COUNTIF but I'd prefer not to add another column if it's possible to count the colours

Edit: Based on responses, I thought I would update with exactly what I require using a test sheet as an example - test sheet can be found at https://docs.google.com/spreadsheets/d/1gAzB-8SX1RnVG26SxgQ5GF2058swl4bQFSq8wSBHjQo/edit?usp=sharing

What I am looking to do is to count the amount of cells in Column B of the Haulage sheet which are highlighted in yellow with red text. The result of this will show in cell P2 of the Stats sheet. However, this result should also be impacted by only showing the count for results that show in the Date Filter sheet (this sheet is controlled by changing the dates in C1 and C2 of the Stats sheet).

So to give you an indicator of the outcome that should occur - if the date range is 18/05/23 - 18/05/23 the result should be 12. If it is 19/05/23-19/05/23 the result should be 2. And if the range is 18/05/23 - 19/05/23 the result should be 14.


Solution

  • You may try:

    =counta(ifna(filter(Haulage!B2:B,map(Haulage!B2:B,lambda(Σ,if(Σ="",,countif(Haulage!B2:B,Σ)-countif(Haulage!B2:Σ,Σ)+1)))=1,isbetween(Haulage!A2:A,Stats!C1,Stats!C2))))
    

    enter image description here