logo elektroda
logo elektroda
X
logo elektroda

[Solved] Excel counting how many cells the background color is red and the value 4 at the

mar-ilo 10899 9
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17163951
    mar-ilo
    Level 12  
    Hello!
    I have an excel file like this:
    Excel counting how many cells the background color is red and the value 4 at the

    I was able to use the function to program that automatically counts how many times each person listed in column K appeared in column C, automatically count me how many times a specific card with numbers 1-15 from column N appears in column B, now I need to automatically counted me how many times for a particular number from column N appearing in column B in the range D6: E111 there is a field with a red background color.
    in the P column it is to count how many times "1" has a red background, if "2" is red it is to count in Q etc.

    I am asking for help in programming the function, I do not know how to make it count based on the background color.

    Attached I add a file to further illustrate the problem. Fields P6: S19 I filled in manually to show how it is to be calculated in the end.
  • ADVERTISEMENT
  • #2 17164183
    Prot
    Level 38  
    Use a simple custom function for this
    Code: VBScript
    Log in, to see the code


    Basic color indexes: red - 3; green - 4 (but check the color tone because they will either have a different index or are not in the palette)
  • ADVERTISEMENT
  • #4 17165679
    mar-ilo
    Level 12  
    I introduced in cell S8 (I added 2 columns and 2 lines in relation to the sample file) the following formula = COUNT CONDITIONS ($ E $ 8: $ E $ 113; $ S $ 7; $ B $ 8: $ B $ 113; $ Q8) which checks times the card number is listed in column B and how many times there is 1 in the given range, I am not sure exactly how and when using which function exactly to add the formula checking the color NumerColor (E8: E113; 3), so that it calculates only for a specific numbers of red boxes.

    When I add it as another condition:
    = COUNTIFS ($ E $ 8: $ E $ 113, $ S $ 7, $ 8 $ b: $ B $ 113, $ Q8; E8: E113; LiczKolor (E8: E113 3))
    although colored only have one field in this range returns 5
    Excel counting how many cells the background color is red and the value 4 at the

    will anyone with more knowledge help? unfortunately I have stalled ...
  • #5 17165755
    Prot
    Level 38  
    As I answered you at PW

    If you read all the entries from your thread carefully (also from the linked one) then you would have a large mine of knowledge about "counting colors" :please:

    To begin with, it must be established that:
    - methods for counting cell background colors only apply to manual formatting or macro formatting - they do not apply to conditional formatting at all :cry: ;
    - what version of Office you are working in - from version 2007 it is possible to filter by color and indirectly to count background colors;
    - what you want to get through your formula:
    = IF (VLOOKUP ($ N $ 8; B8: B21: 1); LiczKolor (D8 :D 21; 3), "")
    parse: a test expression can have only two outputs: TRUE or False -
    and your SEARCH :?: - if it was created correctly it will give you only the result
    value of the "found" cell in the search range i.e. = $ N $ 8 or error # N / A! if in this range this value will not be (as in your sample file) :D

    Added after 5 [hours] 53 [minutes]:

    mar-ilo wrote:
    = COUNT CONDITIONS ($ E $ 8: $ E $ 113; $ S $ 7; $ B $ 8: $ B $ 113; $ Q8) which checks how many times the card number is listed in column B and how many times in the given range there is 1,

    To be precise, this formula only counts those cases where both conditions are simultaneously met - "card number" = 1 and "answered question" No. 1 - :D
    mar-ilo wrote:
    = COUNTIFS ($ E $ 8: $ E $ 113, $ S $ 7, $ 8 $ b: $ B $ 113, $ Q8; E8: E113; LiczKolor (E8: E113 3))
    although colored only have one field in this range returns 5

    The COUNTIF CONDITIONS function (Range1; Condition1; Range2; Condition2; ...) has a strict structure and you cannot enter the wrong highlighting criterion without specifying the range3 :cry:

    To prepare some sensible formula - I would need to understand how it should work :?: Who On what basis? Colors these cells red? Can it be marked differently?
  • ADVERTISEMENT
  • Helpful post
    #6 17166643
    adamas_nt
    Moderator of Programming
    Now that VBA, you can expand the "CountColor" function to "CountColorIf", e.g.
    Code: VBScript
    Log in, to see the code

    Then in P21 you enter:
    Code: Text
    Log in, to see the code
    and drag to the right.

    A similar function (adding variables) you can "count small" in the range P6: S20, and leave the summation as it is.
  • ADVERTISEMENT
  • #7 17166877
    lanzul
    Level 30  
    Prot wrote:
    ... the methods for counting cell background colors only apply to manual formatting or macro formatting - they do not apply to conditional formatting at all ...

    Free my "observation":
    One can only tell if " at all "a color is applied in conditional formatting, referring to, for example, no color at all, and even provide the number of that color, e.g.
    Code: text
    Log in, to see the code

    "you can't" say (probably in 99% of cases?) or just at this moment it is displayed.
    In case of very simple formulas probably it is feasible, because one might be tempted to analyze:
    Code: text
    Log in, to see the code

    for example:
    Code: text
    Log in, to see the code

    each of the objects:
    Code: text
    Log in, to see the code

    regarding cell content ...

    ... but it really "would like to have to be wanted by someone", sit on it and write a doctoral dissertation, for the sake of satisfaction "moving gray cells", whatever that means or doesn't mean ... :)
  • #8 17170994
    Prot
    Level 38  
    mar-ilo wrote:
    I am asking for help in programming the function, I do not know how to make it count based on the background color.

    After a deeper analysis of your "problem", I come to the conclusion that the easiest solution in your case will be to change the sheet structure :D - using a different layout (e.g. as in the screenshot)
    Excel counting how many cells the background color is red and the value 4 at the2018-04...png Download (43.69 kB)

    will allow you to use the simplest formulas for simple summation or conditional sums to perform the calculations you need :ok:
    protpy..lsx Download (14.18 kB)Points: 1.5 for user
  • #9 17172275
    mar-ilo
    Level 12  
    adamas_nt wrote:
    Now that VBA, you can expand the "CountColor" function to "CountColorIf", e.g.


    It actually counts how many times what value is colored red but for all the rows together and I would like to add that it compares the card number from column N (value 1, 2, 3, 4 etc.) with the items in column B and counts for specific cards. In P6 it would count only colored lines for which in column B there will be 1

    Currently it counts all occurrences of red 1, 2, 3 and 4 and I would like it to count in individual rows when in column N there will be the same value as in column B

    Prot wrote:
    After a deeper analysis of your "problem", I come to the conclusion that the easiest solution in your case will be to change the construction of the sheet - using a different layout (eg as in the screenshot)


    Unfortunately, the file layout cannot be changed, it must remain as it is.
  • #10 17183373
    mar-ilo
    Level 12  
    Many thanks adamas_nt - works great :-)

Topic summary

The discussion revolves around creating a custom Excel function to count cells with a specific background color (red) and a specific value (from column N) within a defined range. Users shared a VBA function, `LiczKolor`, to count cells based on their color index, with red being represented by the color index 3. Additional responses included suggestions for modifying the function to incorporate conditions for counting specific values alongside color, leading to the development of `LiczKolorIf`. The conversation highlighted the limitations of counting colors applied through conditional formatting and emphasized the need for manual formatting to achieve accurate results. Users also discussed the importance of maintaining the original file layout while implementing these functions.
Summary generated by the language model.
ADVERTISEMENT