Referencing a Sumif Function

gloudy31

New Member
Joined
Jan 28, 2016
Messages
7
Hi Helpers,

I'm not sure if this is indeed possible, but thought i'd give it a go as you all have been so helpful in the past. I have two tables in two separate worksheets ("WKST1" and "INV2") as shown below. INV2 references WKST1. In Column D of INV2 I am using a SUMIF equation to total all Remaining material that share the same location, grade, and company from Column F of WKST 1. So, for example, I used the equation
=Sumif(WKST1!F:F,WKST1!D:D,"SteelCore",WKST1!A:A,'INV2'!A4,WKST1!B:B,'INV2'!B4)

in Cell D4 of INV2 to gather the total amount of lbs of material in New York/275F Grade/SteelCore Company.

I would like to know if there is any equation(s) I can use in Column E of INV2 that will gather the P.O. #(s) from WKST1 that contribute to the sum of each Location/Grade/Company combination in INV2? For instance, P.O. #'s 11111 and 22222 from WKST1 make up the 30 lbs that are remaining in New York/Grade 275F/SteelCore Company (Cell D4 of INV2).

I realize this is likely not possible as some of the combinations in INV2 will return multiple P.O. #'s (like in the instance noted above), but was wondering if any of you out there with greater EXCEL minds than my own might have any ideas on alternative ways I could go about doing this???

At first glance i thought it could be accomplished through the use of a Pivot Table, however, that did not solve the problem.

I'd greatly appreciate any advice or feedback any of you could offer.




WKST1:


<tbody>
</tbody>

LocationGradeP.O.#CompanyTotal P.O. (lbs)Remaining on P.O. (lbs)
New York275F11111SteelCore5020
New York275F22222SteelCore3010
New York180F99999ABC Inc6025
New York275F44444ABC Inc105
Chicago180F55555SteelCore5015
Chicago180F66666ABC Inc4015
Chicago180F88888ABC Inc2010
Chicago275F33333ABC Inc155

<tbody>
</tbody>



INV2:

LocationGradeCompanyAmt Grade Remaining (lbs)P.O. #(s)
New York180FSteelCore0
New York180FABC Inc25
New York275FSteelCore30**
New York275FABC Inc5
Chicago180FSteelCore15
Chicago180FABC Inc25
Chicago275FSteelCore0
Chicago275FABC Inc5

<tbody>
</tbody>


<tbody>
</tbody>




=Sumif(WKST1!F:F,WKST1!D:D,"SteelCore",WKST1!A:A,'INV2'!A4,WKST1!B:B,'INV2'!B4)**



Thanks!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
It might be a good idea to use all the cells to the right to return each PO into different cells...

Other than that, would you happen to know the most PO's expected to be returned...?
 
Upvote 0
I would try to avoid whole column references in your formulas. It doesn't apply to every function, but you shouldn't be leaving Excel to possibly evaluate over 1,000,000 rows if you are only using say a few hundred or a few thousand say.

You could try this udf. To implement ..

1. Right click the sheet name tab and choose "View Code".

2. In the Visual Basic window use the menu to Insert|Module

3. Copy and Paste the code below into the main right hand pane that opens at step 2.

4. Close the Visual Basic window.

5. Enter the formula as shown in the screen shot below and copy down.

6. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Function getPO(Data As Range, POCol As Long, _
               LocCol As Long, Loc As String, _
               GrdCol As Long, Grd As String, _
               CoCol As Long, Co As String) As String
  Dim a As Variant
  Dim i As Long
  Dim s As String

  a = Data.Value
  For i = 1 To UBound(a)
    If a(i, LocCol) = Loc Then
      If a(i, GrdCol) = Grd Then
        If a(i, CoCol) = Co Then
          s = s & ", " & a(i, POCol)
        End If
      End If
    End If
  Next i
  getPO = Mid(s, 3)
End Function

Excel Workbook
ABCDEF
1LocationGradeP.O.#CompanyTotal P.O. (lbs)Remaining on P.O. (lbs)
2New York275F11111SteelCore5020
3New York275F22222SteelCore3010
4New York180F99999ABC Inc6025
5New York275F44444ABC Inc105
6Chicago180F55555SteelCore5015
7Chicago180F66666ABC Inc4015
8Chicago180F88888ABC Inc2010
9Chicago275F33333ABC Inc155
WKST1





The arguments for the function are, in order:
The range containing the columns of interest from the 'WKST1' sheet. I've used A$1:D$1000. You need to ensure the $1000 is at least as big as any data you will have.
The column within the above range that houses the PO numbers to harvest (3)
The column within the above range that houses the Locations to check (1)
The 'INV2' cell housing the actual Location value of interest (A2 for the first formula)
The column within the above range that houses the Grade to check (2)
The 'INV2' cell housing the actual Grade value of interest (B2 for the first formula)
The column within the above range that houses the Company to check (4)
The 'INV2' cell housing the actual Company value of interest (C2 for the first formula)

Formula in E2 is copied down.

Excel Workbook
ABCDE
1LocationGradeCompanyAmt Grade Remaining (lbs)P.O. #(s)
2New York180FSteelCore0 
3New York180FABC Inc2599999
4New York275FSteelCore3011111, 22222
5New York275FABC Inc544444
6Chicago180FSteelCore1555555
7Chicago180FABC Inc2566666, 88888
8Chicago275FSteelCore0
9Chicago275FABC Inc533333
INV2
 
Upvote 0
Peter,
That was a pretty slick answer...
I don't really get into VBA, but you sure make it look inviting...
Kudos!!!
 
Upvote 0
Peter,
That was a pretty slick answer...
I don't really get into VBA, but you sure make it look inviting...
Kudos!!!
Thanks for your kind words.
Learning vba was one of the main reasons that I joined & began frequenting the forum. :)
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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