Sum by color background and if another condition

Sonic47

New Member
Joined
May 20, 2020
Messages
5
Hello,

I am trying to write/find a correct vba code able to sum the amount in a colored cell based on two conditions : the color of the background and based on another condition (here the fruit)
You can find a easy table showing the situation :
I want the formula to sum the amount in the cell based on the color yellow and if the fruit if an apple for exemple.
We can see the result below, but made manually.

I found a lot of code able to sum (without second condition) or code able to see the color code of the background, but I am not able to use "SUMIF" with it able to choose based on the fruit directly.

Could you please help me ?


1589981370096.png


Thank you very much.
 
Fantastic thank you... got that working but now I need to know how to pickup other colours e.g. the blue.
Is the 65535 in above formula the colour reference? If so how do I grab colour references for other cells/colours.

TIA, appreciated
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Select a cell with the colour you want & then run this in the Intermediate window of the VB Editor
VBA Code:
?activecell.Interior.Color
 
Upvote 1
Sorry ... when I try and run that in immediate window it prompts me to create/save a new macro :-|
 

Attachments

  • Screenshot 2023-05-17 at 16.21.17.png
    Screenshot 2023-05-17 at 16.21.17.png
    70.8 KB · Views: 8
Upvote 0
Got it with a small function
VBA Code:
Public Function BackGroundColor(rng As Range)
    BackGroundColor = rng.Interior.Color
End Function
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 1

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top