VBA or Formula to return reference until volume is saturated then move on to returning the next referrence

EmmaLS

New Member
Joined
Oct 25, 2017
Messages
1
Hi
This is my first post so I hope I am doing everything correctly.

I have 2 tabs of data one for imports and one for exports. What I need to do is:
If cumulative value of exports is less than the imported volume of shipment 1, return the reference for shipment 1. Once the volume of shipment 1 is exceeded move on to returning the reference of shipment 2 (if some value of shipment 1 is covered but not all then return both the reference of shipment 1 and 2). Continue copying shipment 2 reference until shipment 2 volume is covered in the same way then move on to shipment 3 reference etc...

Below is a simplified version of the data and the column Returned reference is showing what I want to return in that column. Can you please advise the best way to do this?

[TABLE="width: 503"]
<tbody>[TR]
[TD][/TD]
[TD="colspan: 3"]Imports tab
[/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 3"]Exports Tab
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD][/TD]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]Import Shipment
[/TD]
[TD]Reference
[/TD]
[TD]Volume
[/TD]
[TD] [/TD]
[TD]1
[/TD]
[TD]Export shipment
[/TD]
[TD]Volume
[/TD]
[TD]returned Reference
[/TD]
[/TR]
[TR]
[TD="align: right"]2
[/TD]
[TD="align: right"]1
[/TD]
[TD]ab123
[/TD]
[TD="align: right"]10000
[/TD]
[TD][/TD]
[TD]2
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]2500
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD="align: right"]3
[/TD]
[TD="align: right"]2
[/TD]
[TD]ac234
[/TD]
[TD="align: right"]15000
[/TD]
[TD][/TD]
[TD]3
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]450
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD="align: right"]4
[/TD]
[TD="align: right"]3
[/TD]
[TD]ad345
[/TD]
[TD="align: right"]14000
[/TD]
[TD][/TD]
[TD]4
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]300
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD="align: right"]5
[/TD]
[TD="align: right"]4
[/TD]
[TD]ae456
[/TD]
[TD="align: right"]6000
[/TD]
[TD][/TD]
[TD]5
[/TD]
[TD="align: right"]4
[/TD]
[TD="align: right"]760
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD]6
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]6
[/TD]
[TD="align: right"]5
[/TD]
[TD="align: right"]4400
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]7
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"]1480
[/TD]
[TD]ab123
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]8
[/TD]
[TD="align: right"]7
[/TD]
[TD="align: right"]400
[/TD]
[TD]ab123 & ac234
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]9
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]500
[/TD]
[TD]ac234
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]10
[/TD]
[TD="align: right"]9
[/TD]
[TD="align: right"]10000
[/TD]
[TD]ac234
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11
[/TD]
[TD="align: right"]10
[/TD]
[TD="align: right"]4000
[/TD]
[TD]ac234
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]12
[/TD]
[TD="align: right"]11
[/TD]
[TD="align: right"]500
[/TD]
[TD]ac234 & ad345
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]13
[/TD]
[TD="align: right"]12
[/TD]
[TD="align: right"]450
[/TD]
[TD]ad345
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]14
[/TD]
[TD="align: right"]13
[/TD]
[TD="align: right"]6900
[/TD]
[TD]ad345
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]15
[/TD]
[TD][/TD]
[TD]etc….
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


The only way I have of achieving this currently is adding a cumulative volume column and using lots of nested IF statements which doesn't seem the best way. it seems to me a macro could solve this really easily but I am not experienced at building macros from scratch so would really appreciate some help or if you could suggest a formula that will not become overcomplicated and potentially exceeed the number of nested IFs allowed!)

Many Thanks in advance!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the Forum!

I think you're right about the cumulative columns making it easier. Try:

I2: =IF(INDEX(B$2:B$8,1+IFERROR(MATCH(H1,D$2:D$8,1),0))<>INDEX(B$2:B$8,1+IFERROR(MATCH(H2-0.001,D$2:D$8,1),0)),INDEX(B$2:B$8,1+IFERROR(MATCH(H1,D$2:D$8,1),0))& " to ","")&INDEX(B$2:B$8,1+IFERROR(MATCH(H2-0.001,D$2:D$8,1),0)) Copy down


Excel 2010
ABCDEFGHI
1ImportReferenceVolumeCumulativeExportVolumeCumulativeReference
21ab12310,00010,00012,5002,500ab123
32ac23415,00025,00027,50010,000ab123
43ad34514,00039,000350010,500ac234
54ae4566,00045,000476011,260ac234
65xxx1,00046,000515,00026,260ac234 to ad345
76yyy5,00051,000612,74039,000ad345
86zzz20,00071,000740039,400ae456
9850039,900ae456
10910,00049,900ae456 to yyy
11104,00053,900yyy to zzz
121115,00068,900zzz
Sheet1
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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