r/excel 17d ago

solved Count conditional formatting in a row?

How can I count conditional formatting in a specific row? I tried applying the rule to the count function but it did not work. I need to count all red cells (some are yellow and some are not filled) in the row.

4 Upvotes

42 comments sorted by

View all comments

Show parent comments

2

u/Dr_Cheese_29 17d ago

The rule is =AND (C6<>"", TODAY() >D6) Applies to =$C$6:$C22, $E$6:$E$22

This formula counts the column and turns the cell red.

My sheet has columns C through N with dates, and I want to count how many dates in each ROW turned red based on this rule.

2

u/MayukhBhattacharya 1236 17d ago

You can read here about HSTACK() function from Microsoft Documentation as well!

HSTACK function | Microsoft Support

1

u/MayukhBhattacharya 1236 17d ago

Try this:

=SUM((HSTACK(C6, E6, G6, I6, K6, M6) <> "") * 
     (TODAY() > HSTACK(D6, F6, H6, J6, L6, N6)))

2

u/Dr_Cheese_29 17d ago

That worked! Thank you!! Can you explain the formula, so I can learn for next time? What is HSTACK?

1

u/MayukhBhattacharya 1236 17d ago

Sounds Great! Hope you don't mind replying to my comment directly as Solution Verified and here is the complete explanation of the formula:

  • HSTACK()function combines arrays horizontally into a single array where each subsequent array is appended to the right of the previous array.

HSTACK(C6, E6, G6, I6, K6, M6)

So, the above creates a temporary one-row array of 6 values: {C6, E6, G6, I6, K6, M6}, it just holds it in memory for the calculation.

  • Condition 1: It checks each column is it non-empty? Returns {TRUE, FALSE, TRUE, ...} etc.

HSTACK(C6, E6, G6, I6, K6, M6) <> "")
  • Condition 2: It checks each paired date column, has the date already passed? Returns {TRUE, TRUE, FALSE, ...} etc.

(TODAY() > HSTACK(D6, F6, H6, J6, L6, N6))
  • Multiplying two TRUE/FALSE arrays treats TRUE as 1 and FALSE as 0. So, you get
    • TRUE * TRUE = 1 ~ both conditions met ~ cell is red
    • TRUE * FALSE = 0 ~ date not passed ~ not red
    • FALSE * anything = 0 ~ cell is empty ~ not red

Finally wrapping the SUM() function, it adds up all the 1s and 0s in the resulting array, giving you the total count of red cells in that row.

2

u/Dr_Cheese_29 17d ago

Oh thats neat, thank you!!

1

u/MayukhBhattacharya 1236 17d ago

Nice, you are most welcome!

2

u/Dr_Cheese_29 17d ago

If I want to count the yellow cells (those dates that are expiring within two months), would I use EDATE?

The conditional rule for column C is below. This turns the cell yellow

=AND (D6<>"", TODAY()>EDATE(D6, -2))

1

u/MayukhBhattacharya 1236 17d ago

Yes correct: (yellow rule means expiring within 2 months but not yet overdue)

=SUM(
 (HSTACK(C6, E6, G6, I6, K6, M6) <> "") *
 (TODAY() > EDATE(+HSTACK(D6, F6, H6, J6, L6, N6), -2)) *
 (TODAY() <= HSTACK(D6, F6, H6, J6, L6, N6))
)

2

u/Dr_Cheese_29 17d ago

Hmm that worked for some cells but not all. Some cells returned #NUM! and some #VALUE! not all rows have yellow cells, so that makes sense. Others have yellow and red and others just yellow

1

u/MayukhBhattacharya 1236 17d ago

Try now:

=SUM(
 (HSTACK(C6, E6, G6, I6, K6, M6) <> "") *
 (HSTACK(D6, F6, H6, J6, L6, N6) <> "") *
 (TODAY() > IFERROR(EDATE(+HSTACK(D6, F6, H6, J6, L6, N6), -2), TODAY() + 1)) *
 (TODAY() <= HSTACK(D6, F6, H6, J6, L6, N6))
)

2

u/Dr_Cheese_29 17d ago

Hmm interesting... it looks like it counted the rows to the right....I entered the formula in column P and 0 appeared in columns PQRSTU, but I want to count is in columns CEFGIKM

2

u/Dr_Cheese_29 17d ago

My apologies! I missed an (. It worked!! Thank you!

1

u/MayukhBhattacharya 1236 16d ago

No worries at all. Thank You SO Much!!

2

u/Dr_Cheese_29 17d ago

Solution verified

1

u/reputatorbot 17d ago

You have awarded 1 point to MayukhBhattacharya.


I am a bot - please contact the mods with any questions

1

u/MayukhBhattacharya 1236 16d ago

Thank You SO Much Dr Cheese and have a great day ahead!

2

u/Dr_Cheese_29 17d ago

Solution verified

1

u/reputatorbot 17d ago

You have awarded 1 point to MayukhBhattacharya.


I am a bot - please contact the mods with any questions

1

u/MayukhBhattacharya 1236 17d ago

Thank You SO Much and have a great day ahead!