Forum Discussion

Andre-Vassoigneur's avatar
Andre-Vassoigneur
Copper Contributor
Jun 06, 2019
Solved

If function based on cell color

Hello, I don't know how to use VBA to do a calculation based on cell color. My goal is to know which expense is related to which account in order to have the balance of each account separately. To...
  • Zack Barresse's avatar
    Jun 06, 2019

    Andre-Vassoigneur hello. Simply put, you can't do this. There is no current function to aggregate by cell color. There are some workarounds though:

    1. Add a helper column*
    2. Write your own function
    3. Table data and filter by color

    * This is typically the best way as it gives you data in an adjacent cell which you can write conditions on. For example, with your data, if you inserted a column between C and D, and put either "Personal" or "Company" in D7:D14, you would have a column you could use as a condition in which to aggregate. You could even hide that column afterwards if you didn't want to see it.

     

    Assuming you inserted a column, that would make your current column E now be in F, and your current column F be in G. So the formulas would be:

     

    Column F (Personal account):
    =IF(D7="Personal",E7,0)

     

    Column G (Company account):
    =IF(D7="Company",E7,0)

     

    Your total balance [column] would stay the same.

Resources