Alternative to lookup formulas

MissingInAction

Board Regular
Joined
Sep 20, 2019
Messages
85
Office Version
  1. 365
Platform
  1. Windows
Hi everyone. I'm looking for an alternative to the lookup formula. Here is some background. The Excel sheet is for a landfill site, so every time waste gets dumped, the entry gets assigned a unique sequential number. On the invoicing sheet I have calculations to determine how much each company must pay for the waste they dumped. On the invoice it should also list all the sequential numbers relevant to waste that must be paid for (some waste types are free to dump, so they don't need to be listed.) This is where the lookup formula alternative comes in. I had a lookup formula that worked, but now it doesn't anymore and I don't know how to fix it. It also slows down Excel quite a bit.

I have tried vlookup and xlookup, but it only lists the first entry its find not the list. Hope I explained it well.
 
You can also use SUMPRODUCT in a similar way, and, for the benefit of others reading this thread, you don't need Office 365, SUMPRODUCT has been around in Excel for years. I use it, or a combination of INDEX and MATCH, depending on the complexity of the data.

The multiplication of the Company Name, Product, and Transaction Code results is used to determine if the Net Weight data in a particular row in the array should be added. TRUE and FALSE results are converted to 1 and 0. Any result that returns FALSE will result in an overall product of 0 for a row, and the data for that row will not be added. The data for any row will only be added if all the criteria results in that row translate to TRUE, and therefore 1.

There are hundreds if not thousands of articles online that explain how to use SUMPRODUCT, which can also incorporate an OR criteria, I'm not sure if FILTER can do that. Just google "Excel sumproduct function explained".
 
Upvote 0

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Thank you for the info. I'll have a more in depth look at the posts as soon as I can.
Just to clarify, I do not need the formula to look up the weight, it needs to look up the transaction code of the selected company. Kinda like a pivot table would do. I then have a different formula determining if the waste type of the transaction code, returned by the previous formula, is a type of waste that must be paid for.
 
Upvote 0
That was an example to demonstrate the use of SUMPRODUCT. If you just need to lookup a transaction code based on one cell value, the selected company, a simple combination of INDEX and MATCH will work fine. VLOOKUP will not work if the data is not sorted alphanumerically. INDEX and MATCH work whether the data is sorted or not. Like this:

=INDEX(H6:H10,MATCH(E6,G6:G10,0),1)
EFGH
Selected Company:Result:companytranscode
6​
DEF CorporationmnopXYZ Companyabcd
7​
Any Company, LLCefgh
8​
Some Other Companyijkl
9​
DEF Corporationmnop
10​
B.D. Company, Inc.bcdz
 
Upvote 0
Hi Jerry. That formula looks promising. If a company has more than one transaction number, how do I get it to list the 2nd, 3rd, etc. transaction code?
 
Upvote 0
I believe if there are more than one unique transaction codes for a particular selected company you would need to run a macro to create a list of those codes for that company.

The other option would be to analyze the data and determine the maximum count of different transaction codes any company would have, or would ever likely have, which could be done with a SUMPRODUCT function, then create a table with multiple functions. So if you would realistically only ever have a maximum of 5 (for example) different codes for any company, instead of just one function you would have 5 rows of that function. It would have to be modified to prevent duplicate codes in subsequent rows, which should not be difficult.

To prevent misleading information, because suddenly one day there are 6 codes for a company, you could test whether you have sufficient functions by counting the number of existing functions compared to the new quantity of unique codes for each company. That could be placed at the top of your worksheet with conditional formatting to highlight the difference and notify you that you need to expand the number of rows of functions to accommodate the new maximum number of unique codes.

If I were doing this, I would create a macro to make a list of all the codes for a selected company.
 
Upvote 0
Thanks, but that seems like more effort than it is worth. I managed to fix the lookup formula in the mean time, so thanks everyone for the suggestions.
 
Upvote 0
OK, just remember that VLOOKUP will not work properly if your data range is not sorted.

I worked out a non-macro solution using a combination of MATCH and INDEX functions, and also highlighted when duplicate codes exist for a company.

I am trying the Mini-sheet upload for the first time, so please bear with me...

find company codes.xlsx
DEFGHIJKLMNO
32 More Result Rows NeededDuplicate Codes Exist <---- Modify the formulas in D3 and E3, and column O, to accomodate the entire number of rows as applicable when company data and/or the company list, or the range of Results formulas, is expanded
4
5Selected Company:Result:DuplicatesCompanyTrans CodeCompany ListExtra Result Rows Needed
6DEF Corporation8ABCDABCDXYZ Company10WWAny Company, LLC 
717EFGH XYZ CompanyABCDB.D. Company, Inc. 
8If more rows are needed19ABCDABCDDEF CorporationABCDABC Company, Inc. 
9for the Result formulas,21LMNO Any Company, LLCABCDSome Other Company 
10as shown in D3 above,B.D. Company, Inc.ACW3XYZ Company 
11select the last row ofB.D. Company, Inc.ACW9JJ, Inc. 
12formulas in G thru I andB.D. Company, Inc.ACW3DEF Corporation2
13drag them down theB.D. Company, Inc.BC1Z
14number of rows needed.ABC Company, Inc.EF12
15Some Other CompanyEF12
16Any Company, LLCEFGH
17DEF CorporationEFGH
18Some Other CompanyEF13
19DEF CorporationABCD
20JJ, Inc.IJKL
21DEF CorporationLMNO
22DEF CorporationABCD
23JJ, Inc.EFGH
24DEF Corporation99ZZ
25JJ, Inc.IJKL
Sheet1
Cell Formulas
RangeFormula
D3D3=IF(SUM(O6:O12)>0,MAX(O6:O12)&" More Result Rows Needed","Result Rows are Sufficient")
E3E3=IF(COUNTA(I6:I10)-COUNTIF(I6:I10,"")>0,"Duplicate Codes Exist","No Duplicate Codes")
G6:G9G6=IF(G5=COUNTA($K$6:$K$25)+ROW($K$5),"",IFERROR(MATCH($E$6,INDIRECT(ADDRESS(G5+1,COLUMN($K$5))&":"&ADDRESS(COUNTA($K$6:$K$25)+ROW($K$5),COLUMN($K$5))),0)+G5,""))
H6:H9H6=IFERROR(INDIRECT(ADDRESS(G6,COLUMN($L$6))),"")
I6:I7I6=IF(ROW(H6)=ROW(H$6),IF(ISERROR(MATCH(H6,H7:H$25,0)),"",H6),IF(ROW(H6)=ROW(H$25),IF(ISERROR(MATCH(H6,H5:H$6,0)),"",H6),IF(AND(ISERROR(MATCH(H6,H5:H$6,0)),ISERROR(MATCH(H6,H7:H$25,0))),"",H6)))
I8:I9I8=IF(ROW(H8)=ROW(H$6),IF(ISERROR(MATCH(H8,H9:H$25,0)),"",H8),IF(ROW(H8)=ROW(H$25),IF(ISERROR(MATCH(H8,H$6:H7,0)),"",H8),IF(AND(ISERROR(MATCH(H8,H$6:H7,0)),ISERROR(MATCH(H8,H9:H$25,0))),"",H8)))
O6:O12O6=IF(COUNTIF($K$6:$K$25,N6)-COUNTA($G$6:$G$9)<=0,"",COUNTIF($K$6:$K$25,N6)-COUNTA($G$6:$G$9))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
L22Expression=K22:K38=$E$6textNO
L25Expression=K25:K41=$E$6textNO
L23Expression=K23:K39=$E$6textNO
L24Expression=K24:K40=$E$6textNO
K23:K25Expression=K23:K39=$E$6textNO
K22Expression=K22:K38=$E$6textNO
O6:O12Cell Value<>""textNO
L6:L21Expression=K6:K22=$E$6textNO
K6:K21Expression=K6:K22=$E$6textNO
Cells with Data Validation
CellAllowCriteria
E6List=$N$6:$N$12
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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