Solved

Creating a string with all cells that meet criteria for SUMIF formula

Posted on 2011-03-02
12
312 Views
Last Modified: 2012-06-27
Hi Experts,

I've got a SUMIF formula I'm using to search a table and sum any line items which have a certain value in Column A.

Example:

ColA: Type      ColB: Name            ColC: Cost
Child            John1                  $100
Adult            John2                  $200
Child            John3                  $150
Adult            Jane4                  $300
Child            Jane5                  $75
Child            Jane6                  $50

So, SUMIF (A:A, "Child", C:C)= $375

What command / formula can I use now to create a list of all the names associated with that summation in a cell as a string?  In the above example, I want to know that the cost of "$375" is associate with "John1, John3, Jane5, Jane6, "

Thanks,
Ravi
0
Comment
Question by:rav_rav
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 3
12 Comments
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 35018753

Use this formula...

=Sumproduct((A1:A100="Child")*(b1:b100="John1")*(C1:C100))

Saurabh...
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 35018760

Ravi,

Also please adjust the ranges as per your data.

Saurabh...
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35018767
You would need VBA - is that OK?
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 

Author Comment

by:rav_rav
ID: 35018858
Hi Saurabh,

Thanks for the quick response, but could you explain your formula?  I tried it using the above sample data and I'm not getting a string value.


0
 

Author Comment

by:rav_rav
ID: 35018877
VBA is fine, but I would prefer a formula if possible.
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35019056
You can use a function created in VBA so it works the same as a formula, but in order to use a native formula you would need a whole bunch of helper cells since there is no array concatenation function.
0
 

Author Comment

by:rav_rav
ID: 35019123
Hi rorya,

Your suggestion makes sense.

What would the function be in VBA?
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 35019155

Ahh sorry i thought you are looking for option how to sum values, In other way if you want to find out no. of parameters which matches the creteria you will either need to use a macro or you can create a pivot of it which automatically provide you details about what you are looking for...
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 35019213
Like so:
Public Function ConcatIf(rngCrit As Range, crit, rngData As Range, Optional strSeparator As String = ",") As String
   Dim lngindex As Long

   For lngindex = 1 To rngCrit.Cells.Count
      If Len(rngData(lngindex).value) > 0 And rngCrit(lngindex).value = crit Then ConcatIf = ConcatIf & strSeparator & rngData(lngindex).value
   Next lngindex
   If Len(ConcatIf) > 0 Then ConcatIf = Mid$(ConcatIf, Len(strSeparator) + 1)
End Function

Open in new window


Used:
=CONCATIF (A:A, "Child", B:B)

Note: it would be best to use specific ranges rather than entire columns.
0
 

Author Comment

by:rav_rav
ID: 35023950
Hi rorya,

Quick question:  what's the last line "If Len(ConcatIf) > 0 Then ConcatIf = Mid$(ConcatIf, Len(strSeparator) + 1)" used for?

Thanks
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 35024812
It removes the leading comma (or other separator) from the returned string.
0
 

Author Comment

by:rav_rav
ID: 35027215
Thanks rorya
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question