Sum of vlookup in multiple rows with condition

balaba

New Member
Joined
Feb 24, 2021
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi,

Let me try and explain what I need with a simplified example:


I have a table (H3:I5) that gives me the value for each item (I have dozens of items in the reality).
I need, for each month (in B9, C9, D9), to know the sum of the value of each item for the particular month... but only counting the cells that are NOT in yellow.

For example, for January, it would be:
Apple: 3
Orange: do not count
Banana: 2
Banana: 2
Banana: do not count
Apple: 3
TOTAL=10 -> this is the value that I need

I can't do a formula with vlookup+vlookup+vlookup...

For the color part, I have created a new function (via macro) "colorindex", that gives me the color index of a cell (ex: colorindex(B3) would give me "6" as yellow is color coded as 6 in Excel).

thanks for you help!
 

Attachments

  • capture excel.PNG
    capture excel.PNG
    11.6 KB · Views: 35

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi & welcome to MrExcel.
Can you post the code for your UDF
 
Upvote 0
Hi,

I don't think there is a formula that allow you to total the column and cells without counting the coloured cells. But I am welcomed to be corrected.

You would need to create a new reference in Formulas > name manager > New.
Then provide a name of the reference and then enter in the scopes to: GET.CELL(38,Sheet1!B2) > hit OK

Then you need to press the equals key against your data(Say your data starts from B2 then press the equals key in C2) and then click to find your named reference and drag it down to the end of the column.

You would need insert a new column against your data for each separate one.

Then you can use the countif function using your reference as the range without including the number 6.

Hopefully this would help if you do not wish to use VBA.
 
Upvote 0
@MrD31
The OP already has a UDF for finding the coloured cells..
 
Upvote 0
Hi & welcome to MrExcel.
Can you post the code for your UDF
Hi, thank you!

see below:

Function ColorIndex(CellColor As Range)

ColorIndex = CellColor.Interior.ColorIndex

End Function
 
Upvote 0
Ok, if you change your UDF to
VBA Code:
Function ColorIndx(CellColor As Range) As Variant
   Dim Cl As Range
   Dim i As Long
   Dim Ary As Variant
   ReDim Ary(1 To CellColor.Count, 1 To 1)
      For Each Cl In CellColor
         i = i + 1
         Ary(i, 1) = Cl.Interior.ColorIndex
      Next Cl
      ColorIndx = Ary
End Function
you can use it like
+Fluff 1.xlsm
ABCDEFGHI
1JanuaryFebruaryMarch
2AppleOrange
3OrangeBananaApple3
4BananaOrangeOrange5
5BananaAppleBanana2
6BananaApple
7AppleApple
8
91018
10
Master
Cell Formulas
RangeFormula
B9:C9B9=SUM(IF(colorIndx(B2:B7)<>6,XLOOKUP(B2:B7,$H$3:$H$5,$I$3:$I$5),0))
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,908
Messages
6,181,671
Members
453,060
Latest member
DeramasJonnel

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