VBA: Creating UDF for Sumifs by colour and price point

chengmans123

New Member
Joined
Jul 7, 2020
Messages
1
Office Version
  1. 365
Hi Everyone,
I've found codes online to help me Sumifs by colour for situations where the column with coloured data is to be summed.
However, i'm looking Sumifs by multiple criteria across different columns. See example below.
1594133065329.png

1594133428553.png


I have the following code to countifs by colour and price points
If Price Point = Purple, Price Point = $7.99 then count the number of weeks on $7.99
VBA Code:
Function COUNTIFCOLOUR(Colour As Range, UnitPrice As Range, rng As Range) As Long

Dim NoCells As Long
Dim cellColour As Long
Dim rngCell As Range
cellColour = Colour.Interior.Color

For Each rngCell In rng
    If rngCell.Interior.Color = cellColour And rngCell.Value = UnitPrice Then
       NoCells = NoCells + 1
    End If
Next
COUNTIFCOLOUR = NoCells
End Function

I want to create a function where it does something similar but instead of counting it sums up the column "Unit Sales"

ie. If Price Point = Purple, Price Point = $7.99, then sum the column "Unit Sales"

A function that will give me the number "527 Units" in the picture above.

Thank you for taking the time to read this post!
 

Attachments

  • 1594133102878.png
    1594133102878.png
    3.3 KB · Views: 5
  • 1594133289244.png
    1594133289244.png
    2 KB · Views: 5

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I have done something similar before. UDFs are slow. It is best to create a hidden helper column that provides the status you need. If you have conditional formatting, you can create a status to give you the same. Then SUMIFS is a true function and calculates much faster.

My $.02
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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