logo elektroda
logo elektroda
X
logo elektroda

How to Sum Cells in Excel Based on Font Color: Black Paid, Red Unpaid - Easy Method

doncap 14397 12
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 17008900
    doncap
    Level 1  
    Hello
    I have a datasheet, the table has only two font colors, black and red, the color is changed manually (black paid, red unpaid).
    I am looking for a way to easily sum cells in a column based on a defined font color,
    Thank you for your help.
    Dariusz
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #4 17011090
    dariuszb09
    Level 2  
    Hello !!!
    I found something like this:
    Code: VBScript
    Log in, to see the code

    The function in the cell looks like this (= SumCellsByFontColor (search range; cell with font color)
    To update the result of F9
    And now I have a question. How to combine two functions - to sum by font color (shown above) and to sum by cell background color (shown below) so that it sums up by background and font color.
    Code: VBScript
    Log in, to see the code

    Regards Darek.
  • ADVERTISEMENT
  • #5 17011172
    lanzul
    Level 30  
    Insert the "body" one into another, change the name, set as 'Variant', remove duplicate declarations, add separate variables for the font and background - maybe as 'Double', because if you select a few billion cells, 'Long' will not make - assign for the result of the function, a combination of two sums with some determinants as to the font, and as to the background and will work.
  • #6 17011358
    dariuszb09
    Level 2  
    Hello !!!
    Sorry but
    Quote:
    Declarations, variables, 'Double', 'Long'
    it's black magic, for me Excel ends around = if i = search. vertically / horizontally :)
    Anyway, I came to this myself and I am still recognized at work as a SPECIALIST from Excel. I know very little of my knowledge in this subject and VBA is Mary's magic for me, that's why I ask magicians SPECIALISTS for help :)
  • #8 17012890
    JacekCz
    Level 42  
    in my opinion, the problem is wrong from the beginning, the color should result from some basic data, and the same data should result from the sum.
  • #9 17013269
    dariuszb09
    Level 2  
    Hello !!!
    "Lanzul"
    I know that you devoted your time to this function and the spreadsheet but that was not what I meant. I want it to sum (values) only e.g. cells with a blue background and yellow font,
    and separately with purple background and yellow font and separately green background and yellow font or blue background and red font, blue background and green font etc.
    font and background color are best to be given as in the functions above in separate cells.
    Regards Darek.
  • #10 17013693
    lanzul
    Level 30  
    dariuszb09 wrote:
    ... but that's not what I meant. I want it to sum (values) only e.g. cells with a blue background and a yellow font ...

    As you write, they understand you that way - is there no "no" in the above sentence or is there too much "only"?

    dariuszb09 wrote:
    ... I want it to sum (values) (? ...?) e.g. cells with a blue background and a yellow font, and separately with a purple background and a yellow font and separately a green background and a yellow font, or a blue background and a red font, a blue background and green font etc. The font color and background should ideally be given as in the functions above in separate cells

    1. And how do I add up? That's right, you have patterns in separate cells ... :) ... only that the disadvantage of this function is that it does it based on a pattern (everyone does this), which you must select, which is in a cell, and which is not entered in the function call as an argument of "enter the amount of blue with yellow ".

    2. You entered the "problem" yes and no different, you gave the "material" for processing, read what you wrote ... you did not specify other criteria, and I do not intend to guess ... :D ...

    3. And then what do you mean by "sum" - the content of cells meeting the criteria? The number of these cells? By selecting the appropriate optional numeric argument you designate this function for what to count. Just as I write, the function does it after the pattern taken from the pattern cell, and not on the basis of manually entered arguments of the type vb blue, vb yellow, vb white, etc.

    4. If you think about the "automatic" recognition of colors by a function, without specifying its pattern ("in words", indicating the range of conditions), then ... :D ... how many colors do you think she should recognize?
    For RGB there are probably 16 777 216 (for other systems, e.g. CMYK is 4 294 967 296) ... :) ...
    In old Excel, 56 are basic (+ 1 "colorless") - Check how much you have in your new ... :D ...:
    Code: text
    Log in, to see the code


    Use links from adamas_nt and Zbych034 , exercise a little ... cells ... :) ...
  • ADVERTISEMENT
  • #11 17013903
    adamas_nt
    Moderator of Programming
    My way, both conditions of both found functions must be met.
    Modified, it will just look:
    Code: VBScript
    Log in, to see the code
  • #12 17014089
    dariuszb09
    Level 2  
    Hello !!!
    "Adamas_nt"
    Many thanks for helping a layman in the field of VBA.
    I checked the work it should. Thanks again :)
    Regards Darek.
  • #13 21313586
    pseudocfoch
    Level 2  
    Check for Python's XlsxWriter library.

Topic summary

The discussion revolves around summing cells in Excel based on font color, specifically differentiating between black (paid) and red (unpaid) text. Users share a custom VBA function, `SumCellsByFontColor`, which sums values in a specified range based on the font color of the cells. The function requires a reference cell with the desired font color. Some participants suggest combining this function with another that sums based on cell background color, leading to a more complex function that checks both font and background colors. There are also inquiries about modifying the function to accommodate multiple color conditions. Overall, the conversation highlights the challenges and solutions related to using VBA for color-based calculations in Excel.
Summary generated by the language model.
ADVERTISEMENT