Formula/VBA for lookup to return a value if a combination of items in a list equal a defined value

JWill78

New Member
Joined
Feb 13, 2015
Messages
10
I am trying to work out a way of doing a lookup whereby the formula/VBA returns a value for a given reference on sheet 1 if one or a combination of values with that reference on sheet 2 add up to a defined value with that reference on sheet 1. By way of example:

[TABLE="width: 351"]
<tbody>[TR]
[TD]Sheet one[/TD]
[TD][/TD]
[TD][/TD]
[TD]Sheet two[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: center"]Col A[/TD]
[TD="align: right"]Col B[/TD]
[TD][/TD]
[TD="align: right"]Col A[/TD]
[TD="align: right"]Col B[/TD]
[TD="align: center"]Col C[/TD]
[/TR]
[TR]
[TD]Reference[/TD]
[TD="align: right"]Amount £[/TD]
[TD][/TD]
[TD]Reference[/TD]
[TD="align: right"]Amount £[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]12345[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD="align: right"]12345[/TD]
[TD="align: right"]20[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]12346[/TD]
[TD="align: right"]200[/TD]
[TD][/TD]
[TD="align: right"]12345[/TD]
[TD="align: right"]50[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: right"]12347[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD="align: right"]12345[/TD]
[TD="align: right"]50[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]12346[/TD]
[TD="align: right"]200[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]12347[/TD]
[TD="align: right"]150[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]12347[/TD]
[TD="align: right"]150[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


So, in the above example I want to be able to do a lookup in sheet 1 to sheet 2 for e.g. ref 12345 where the corresponding value/values for that reference in sheet 2 sum to the given value in sheet 1. So for ref 12345 I'm trying to get a formula that confirms that a combination of the amounts for ref 12345 in sheet 2 add up to £100 (even though the total for that reference is greater than £100).


I have worked out formula to tell me where the total for 12345 in sheet 2 is £100 but can't figure out how to show it where the total for a given reference is not equal to the target amount but a combination of items with that ref are.


If the above is possible I would also like to be able to show on sheet 2 those items in the list that add up to the target value in sheet 1. So in the example above, I am looking for a formula/VBA that would add in the '1s' in column C indicating that these amounts equal the target £100.


The spreadsheets I am working with have thousands of references and tens of thousands of repetitions (in sheet 2) so trying to manually match one sheet to the other isn't really an option. All suggestions gratefully received.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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