Sumproduct of unique values in multiple ranges

Dan5977

Board Regular
Joined
Aug 7, 2008
Messages
111
Office Version
  1. 2010
Hi guys,

Hope you can help. I have a rather complicated (by my standards) spreadsheet and am stuck at this point. Example of type of problem shown below.

sgqzq1.jpg


So I have 3 ranges of data which each have a quantity and a length. I want to create from these ranges a list of unique values with the total quantity required of each value (as shown). Inputs on any column may be blank but where there is a length, there will be an adjacent quantity to the left.

I'm using Excel 2010.

As always, any assistance would be appreciated.

Thanks,

Dan.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
[TABLE="width: 294"]
<tbody>[TR]
[TD="class: xl64, width: 66, bgcolor: transparent"]Qty[/TD]
[TD="class: xl64, width: 66, bgcolor: transparent"]Length[/TD]
[TD="class: xl64, width: 66, bgcolor: transparent"]Qty[/TD]
[TD="class: xl64, width: 66, bgcolor: transparent"]Length[/TD]
[TD="class: xl64, width: 66, bgcolor: transparent"]Qty[/TD]
[TD="class: xl64, width: 66, bgcolor: transparent"]Length[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]3500[/TD]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]3000[/TD]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]980[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]3020[/TD]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]1000[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]3020[/TD]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]1000[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]3500[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]1243[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]2500[/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]3500[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]7[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl66, bgcolor: transparent"]Desired Result[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]4[/TD]
[TD="class: xl65, bgcolor: transparent"]3500[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]3000[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]4[/TD]
[TD="class: xl65, bgcolor: transparent"]3020[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]980[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]1000[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]1[/TD]
[TD="class: xl65, bgcolor: transparent"]1243[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
[TR]
[TD="class: xl65, bgcolor: transparent"]2[/TD]
[TD="class: xl65, bgcolor: transparent"]2500[/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[TD="class: xl65, bgcolor: transparent"][/TD]
[/TR]
</tbody>[/TABLE]

Add the following code for ARRAYUNION function to your workbook, using Alt+F11.

Now define LenghtData by means of Formulas | Name Manager as referring to:
Rich (BB code):
=arrayunion(Sheet1!$B$2:$B$7,Sheet1!$D$2:$D$4,Sheet1!$F$2:$F$6)

And define Ivec as referring to:
Rich (BB code):
=ROW(INDIRECT("1:"&COLUMNS(LengthData)))

A11, just enter and copy down:
Rich (BB code):
=IF($B11="","",SUMIF($B$2:$F$7,$B11,$A$2:$E$6))

B11, control+shift+enter, not just enter, and copy down:
Rich (BB code):
=IF(ROWS($B$11:B11)<=$A$9, INDEX(LengthData,
  SMALL(IF(FREQUENCY(IF(LengthData<>"", 
  MATCH("~"&LengthData,LengthData&"",0)),Ivec),Ivec),
  ROWS($B$11:B11))),"")

Addendum. See the workbook that implements the set up of above:
https://dl.dropboxusercontent.com/u/65698317/Dan5977 unque items of a multicolumn range.xlsm

My FREQUENCY CALC in equivalent to $A$9 on the spreadsheet is returning a #NAME? error. I copied Aladin's formula from that cell on the dummy sheet and adjusted the lookup cell accordingly.

Could this be a version issue? I'm using Excel2010. My best guess is that it doesn't know what arrayunion refers to.

Any ideas?
 
Upvote 0
My FREQUENCY CALC in equivalent to $A$9 on the spreadsheet is returning a #NAME? error. I copied Aladin's formula from that cell on the dummy sheet and adjusted the lookup cell accordingly.

Could this be a version issue? I'm using Excel2010. My best guess is that it doesn't know what arrayunion refers to.

Any ideas?

I have no idea what you have been doing. Did you add the ARRAYUNION code to your workbook if you are not using the one I posted?
 
Upvote 0
I have no idea what you have been doing. Did you add the ARRAYUNION code to your workbook if you are not using the one I posted?

Yes. I copied it from the workbook you kindly made into mine. It feels like I'm so close. All the formulas and arrays are in and amended to suit the actual cells. There must just be one issue causing the #NAME? error. I think it relates to arrayunion. It's either that or LengthData but LengthData is defined as you stated too. Everything is spelt correctly and consistently.

Hopefully with a fresh start in the morning it will be more obvious for me!
 
Upvote 0
Yes. I copied it from the workbook you kindly made into mine. It feels like I'm so close. All the formulas and arrays are in and amended to suit the actual cells. There must just be one issue causing the #NAME? error. I think it relates to arrayunion. It's either that or LengthData but LengthData is defined as you stated too. Everything is spelt correctly and consistently.

Hopefully with a fresh start in the morning it will be more obvious for me!

Run Alt+F11.
Choose This Workbook.
Run Insert | Module
Copy the VBA code for ARRAYUNION and paste it into the module pane.
Run File | Close and Return to Microsoft Excel.

If #NAME? still occurs, some definition must be missing.
 
Upvote 0
It works!

Thanks so much for your help and your patience. It's really appreciated.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,915
Members
452,366
Latest member
TePunaBloke

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