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?

Imports tab
Exports Tab
A
B
C
A
B
C
1
Import Shipment
Reference
Volume
1
Export shipment
Volume
returned Reference
2
1
ab123
10000
2
1
2500
ab123
3
2
ac234
15000
3
2
450
ab123
4
3
ad345
14000
4
3
300
ab123
5
4
ae456
6000
5
4
760
ab123
6
6
5
4400
ab123
7
6
1480
ab123
8
7
400
ab123 & ac234
9
8
500
ac234
10
9
10000
ac234
11
10
4000
ac234
12
11
500
ac234 & ad345
13
12
450
ad345
14
13
6900
ad345
15
etc….

<tbody>
</tbody>


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

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
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,215,071
Messages
6,122,963
Members
449,094
Latest member
Anshu121

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