Sumifs with UDF for Sum by Text Color

Agame21

New Member
Joined
Oct 2, 2015
Messages
5
Hello,

This site has been incredibly helpful for me in the past by searching for similar requests by other posters but I could not find an answer to this problem I am facing...

I have been using a UDF I found online to do a sumif based on the text color of the sum range. See below:

Public Function SumByColor(pRange1 As Range, pRange2 As Range) As Double
Application.Volatile
Dim rng As Range
Dim xTotal As Double
xTotal = 0
For Each rng In pRange1
If rng.Font.Color = pRange2.Font.Color Then
xTotal = xTotal + rng.Value
End If
Next
SumByColor = xTotal
End Function

I am now trying to figure out how to combine this with another criteria to only sum if the text is red AND it is Type 1.


Excel 2010
BCDEFG
5TypeCostTotal Red250
61$ 20Red Type1??
71$ 50
82$ 60
91$ 50
101$ 80
113$ 90
122$ 20
Sheet1

Is it possible to combine a UDF with a SumIfs? Do I need another UDF that does both of these? Please help!
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
You might be able to add to the IF statement like this:

If rng.Font.Color = pRange2.Font.Color And rng.Offset(0,-1).Value = 1 Then
 
Upvote 0
You might be able to add to the IF statement like this:

If rng.Font.Color = pRange2.Font.Color And rng.Offset(0,-1).Value = 1 Then

dreid1011,

Thank you very much for the help! This works great for the example I provided. However, I will actually need to do this for more than just one column over.


Excel 2010
BCDE
5TypeCost ACost BCost C
61$ 20$ 30$ 20
71$ 50$ 40$ 40
82$ 60$ 40$ 60
91$ 50$ 50$ 50
101$ 80$ 100$ 90
113$ 90$ 80$ 90
122$ 20$ 20$ 30
13
14Total Red250110170
15Red Type 1
16Red Type 2
17Red Type 3
Sheet1


Rather than offsetting by 1 column every time, is there a way to make it always look to Column B?

Thanks again!
 
Upvote 0
Try this:

And Range("B"& rng.Row).Value = 1
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,792
Members
449,468
Latest member
AGreen17

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