Microsoft Excel LOOKUP function just... doesn't work? - excel

So, I have a fairly involved workbook.
Sheet 1: A database where the user enters a list of instruments as well as some data about the instruments in a vertical column.
Sheet 2: A sheet that contains the exact same information as sheet 1 but displays it in a different format. Automatically populates based on entries from Sheet 1. (Not useful in this question)
There exists a macro on Sheet 1 that is executed by clicking a button. This macro takes every column from Sheet 1 and creates a new Sheet for each column. Each new sheet, Sheet 3, is renamed to the first value in the column of Sheet 1 that it represents.
i.e., There are 4 columns in Sheet 1 with the first value in each column being: LS-ALPHA, LS-BRAVO, LS-CHARLIE, LS-DELTA. My macro will create 4 new sheets called LS-ALPHA, LS-BRAVO, LS-CHARLIE, LS-DELTA.
The first cell (technically H2) on each of the new sheets contains a formula to reference the sheet name.
=MID(CELL("filename",A1),FIND("]",CELL("filename",A1))+1,255)
i.e., H2 on the LS-ALPHA sheet will actually say "LS-ALPHA", H2 on the LS-BRAVO sheet will say LS-BRAVO, etc.
Every other data cell on the new sheet will automatically look up that value on the main sheet (Sheet 1) to determine what column it is from. Then, it will go below that value and get the contents from some cell x rows below.
=LOOKUP(H2,'Database (Cols)'!D2:AN2,'Database (Cols)'!D3:AN3)
This works absolutely perfectly. It does everything well.
Except, not always.
If I rename the columns to "LS-A, LS-B, LS-C, LS-D", it works. If I rename the columns to "LS-AA, LS-AB, LS-AC, LS-AD", it works. If I rename the columns to "LS-AAA, LS-AAB, LS-AAC, LS-AAD", it works.
However, if I rename the columns to something like "LS-TTF, LS-TTD,LS-TSD, LS-TSF" they are all broken somehow.... None of the links on the sheets work any more. Some of them point to the incorrect column if they even do show something. This issue I'm having is incredibly peculiar. I don't know why these names break it in particular, nor do I know what other names would also break it.
What happens when it 'breaks': All of the references seem to find the last available column in the LOOKUP. Three of the four sheets all use values from the fourth column when they aren't supposed to. Then, one sheet just gives me errors (#N/A). When I step through the calculation, it is looking for the correct value in the LOOKUP function, it's just not returning the right thing....
I can't really give much more information without showing you what's happening so I've included a working spreadsheet and a broken spreadsheet. The sheets have been generated from the macro so you don't have to mess with it. The working and broken files are below:
Working: https://drive.google.com/file/d/0B9zbU-BeMQNfSmRrWVhKVW9RN3M/view?usp=drivesdk
Broken: https://drive.google.com/file/d/0B9zbU-BeMQNfd1FUemwxQjQwMEE/view?usp=drivesdk
Note, the echo column is for debugging purposes. I was trying to see if they would all show echo instead of delta. Apparently, they don't.

From the help for the LOOKUP function:
IMPORTANT: The values in lookup_vector must be placed in ascending
order: ..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE; otherwise, LOOKUP
might not return the correct value. Uppercase and lowercase text are
equivalent.
The set of values which work correctly - "LS-A, LS-B, LS-C, LS-D" - are in alphabetical order. The set of values which don't work correctly - "LS-TTF, LS-TTD, LS-TSD, LS-TSF" - are not in alphabetical order. Also, LOOKUP doesn't necessarily find an exact match - as specified in the help:
If the LOOKUP function can't find the lookup_value, the function
matches the largest value in lookup_vector that is less than or equal
to lookup_value.
To fix, either:
reorder the non-working set of values to be in alphabetical order (although you still won't guarantee an exact match), or
switch to using the HLOOKUP function instead. Ensure that the Range_lookup parameter is false to require an exact match. Sample usage: =HLOOKUP(H2,'Database (Cols)'!D2:AN3,2,FALSE)

I had a similar problem because I was wrongly using lookup. To find a value in a vector, I had to use
=MATCH("KEY";F5:F48;0)
instead of
=LOOKUP("KEY";F5:F48)
LOOKUP just didn't work for my objectives.

Related

Multiple Cells Check Without VBA?

So, trying to explain what I need here is my two sheets on the same workbook, Sheet Example:
I need to make a formula for each cell that checks Sheet A "Num_Doc_Ini" and "Num_Doc_Fin" against Sheet B "CHV_CTE_REF", calculates the total after adding up the "VL_DOC" numbers on Sheet B, and finally Checks with "correct" or "Incorrect" after comparing the result to the Sheet A "VL_DOC".
So for example, the second line of Sheet A. I need to make so that check see's the NUM_DOC_INI and FIN so "101 - 102" checks those numbers on Sheet B "CHV_CTE_REF", adds up the "VL_DOC" so in this example 4,159.86 + 4,585.1 that equals = 8,744.96, and then matches it with the "VL_DOC" on Sheet A displaying in this case the text "Correct" and If it does not match displays "Incorrect".
Some lines have few docs to reach like "106 - 108" but there are some that have 10 or more to read and sum up the values, because of that I'm really breaking my mind trying to come up with something.
Is that even possible? I can think of a few ways to use VBA for this but I'm trying to do this all with Cells Formula and because of that I am kinda lost, any help would be appreciated thanks!
Edit:
I'm using excel 2016 atm.
So here is a file for the workbook: https://mega.nz/file/LgVCBbjT#xJnf2HbHd6wdRSNPY7wXSssKv2jZ1-pMsOuKcePlulQ
And the explanation with colors:
I need on the Red Cell a formula to check the numbers of the Blue ones on sheet 1, find them on Sheet 2 (blue cells), add up the VL_DOC (Green ones) on sheet 2, and check them up against the values on Sheet 1 Orange cells (VL_DOC), then print out Correct or incorrect based on the match of the values.
From what I can see in the link, you can use something like the below if you have the newest version of excel (where row ranges and column references are left to your specific case because we can't see them):
=IF(SUM(FILTER(SheetB!$VL_DOC,
(SheetB!$CHV_CTE_REF=SheetA!J2)+(SheetB!$CHV_CTE_REF=SheetA!I2)+...))=N2,
"Correct", "Incorrect")
Then add however many other conditions within the FILTER function you need. For example:
REQUESTED EDIT: If you don't have the newest version of excel, you can just repeatedly use VLOOKUP or INDEX/MATCH however many times is necessary. For example:
=IF(SUM(
VLOOKUP($I2, SheetB!$CHV_CTE_REF, 2,),
VLOOKUP($J2, SheetB!$CHV_CTE_REF, 2,),
...)=$N2,
"Correct", "Incorrect")
SUM, INDIRECT, ADDRESS, MATCH
Note that INDIRECT is a volatile function.
In cell K2 of Sheet 1 of the example workbook, you can use the following formula:
=IFERROR(IF(SUM(INDIRECT(ADDRESS(MATCH(H2,Tabela1[NUM_DOC],0)+1,COLUMN(Tabela1[VL_DOC]),1,1,"Sheet 2")&":"&ADDRESS(MATCH(I2,Tabela1[NUM_DOC],0)+1,COLUMN(Tabela1[VL_DOC]),1,1),TRUE))=J2,"Correct","Incorrect"),"")

Trying to match two lines of text and return a third in excel

I have a couple of different large lists of equipment on seperate worksheets I am trying to consolidate. The first sheet "List" contains multiple columns of information, including one for the area it will be relocated to. Another sheet, "Locations," contains the three areas where each piece of equipment will be relocated to, seperated in to 3 columns; at the top of each column are the names of the locations 2500, 2900, and Term. The issue is, the Equip# from the "List" sheet only partially matches the names on the "Locations" sheet.
List
Locations
As you can see above, A2203-76 under Equip# only partially matches A2203-76 20% NAP TANK AGITATOR.
This is the formula I am using {=INDEX(Locations!$A$2:$C$2,,MIN(IF(Locations!A3:C151="A2203-76",COLUMN(Locations!A:C),0)))}. This unfortunately will only return the first column value, which is 2500. What should happen is: First, on the List sheet, the New Gear Location cell should check the Equip# cell in the same row, after retrieving the Equip# it should go to the Locations sheet and search for a partial match to what it retrieved from the Equip# cell. After finding a partial match, it should look at the column the match was found in and return one of the 3 cell values from the top "2500, 2900, or Term" based on what column it was found in and fill this value in the cell on the List page that the formula was entered in to.
Another issue, which makes me think this may not be possible, is there are also instances of A2203-75. So I question if excel has the ability to apply I guess "weights" to different partial matches. What I am getting at is, if I applied some function to partially match A2203-76 to something on the other page, would it just stop at A2203 and pick the A2203-75? Or would it look at the whole string first and find the correct instance? Maybe my thinking is wrong, but if you could offer any help I would appreciate it.
Is this what you mean?:
=INDEX(Locations!$A:$B,MATCH(List!$A2&"*",Locations!$C:$C,0),COLUMNS($A:A))
Paste this formula in List!B2 and drag right, down.
It searches for your search text followed by wildcard *.
!! Please note that this will return the first match.
If you are searching for A2203-76 and your data also contains A2203-761 it will return this value if it's found prior to A2203-76 !!

Two formulas I'm having issues with

this is my first time asking a question here, but I have two formulas that I'm not really sure why they aren't working.
The first issue I'm having is with this formula:
=MAX(IF(C46:C51<80,B46:B51))
Any reason that this formula returns #VALUE! I'm supposed to find the max value of data in column B so long as the data in column C is less than 80.
Then I'm having issues with VLOOKUP on two questions, that are related I have a large dataset on a separate worksheet. I need to VLOOKUP someone's name to find a value associated with that name. The problem is that their name comes up multiple times. The formula I have for it so far is:
=VLOOKUP('PDR DATA'!E80,'PDR DATA'!A4:V119,15,FALSE)
Where 'PDR DATA'!E80 is the first instance of the person's name appearing. However, using FALSE with VLOOKUP returns #N/A, but if I use TRUE it returns the very last value from column 15 even though the name is different from what I'm searching for. I'm lost here and don't know where to turn.
=MAX(IF(C46:C51<80,B46:B51,C46:C51)) works for me. (Please ensure B46:B51 & C46:C51 has integer values)
=VLOOKUP(cell you want to lookup for, cells where you want to lookup(maybe more than one column), which column you want to fetch from (number), rangelookup) try to understand the syntax and give your inputs
ex: If I have a existing data with Name and id in sheet2, need that id in sheet1 by using the name then I will use =VLOOKUP(L2,Sheet2!A2:B5,2,TRUE)
L2 is the sheet1 name, then I have selected both columns(A,B) and rows in sheet2, then column number is 2.

Excel - Retrieving a cell based off of multiple criteria

I am attempting to return the value of a cell from within a different sheet based upon two cell values in the second sheet.
As an example the Main and Second sheet have three columns each (Item, Code, Number), the difference being that the second sheet has only one row and two drop down lists that are populated with the Item(s) and Code(s) (from the Main sheet - i.e like a database table). From within the Second sheet I would like the Number to be returned from the main sheet, once the Item and Code had been selected from the drop down lists on the Second sheet.
Unfortunately I'm unsure as how to do this based off of multiple criteria. As far as I'm aware VLOOKUP only used one criteria over a range. I've attempted the following below which is accepted by Excel as a valid formula, however it doesn't return the correct value.
{=SUMPRODUCT((Main!A:A='Second'!A7) * (Main!C:C='Second'!E2) * (Main!G:G))}
I've interpreted the above as the first two sets of brackets being the range and condition to match and the last set being the range of values to return from. Is this a correct assumption and is this the correct use of that function?
Are there any other functions I could use?
Thank you, I have very little experience with Excel!
Have you taken a look at the magic INDEX combined with MATCH, and perhaps MATCH again?
INDEX returns the contents of a cell from a table provided a row and a column. Usage:
=INDEX([table to look in]; [COLUMN index]; [ROW index])
MATCH returns the indexes that match a criteria in the table. Usage:
=MATCH([Criteria];[table to look in])
And you can nest one inside the other the following way:
=INDEX([table to look for in];MATCH([Criteria];[Table to look for the particular Row]);[COLUMN, or a second MATCH to find the right column])
Or even combine a couple of MATCH as in
=INDEX([table to look for in];AND(MATCH(1);MATCH(2)); [Column to look for, or MATCH to look for in column])
Which I think is what you want.
If you need a SUM of something (as you used a SUM function before), just nest it inside the proper SUM function

VLookUp with Nested SUMIFS

I have been trying to make a form for some of my team members who are not that computer literate, and I essentially want to make it click and go. I thought I could do it...but alas I am not as good with nesting functions as I thought I was.
I have this spreadsheet where I want to put data into the yellow cell. On the next sheet I have the below table. What I want to do is use a formula to fill H4 with the "Request Branch's" Account Number. Now, I have currently filled the cells with information. They, in fact, have drop down options - which are pulled from the Account List table. As a result the value in H4 will continually change based on the needs of the user - but must be within the confines of the Account List Table.
What I have tried is here and enter link description here. I keep getting result of #Value, or N/A. I can't figure out what I am doing wrong. I know that I need to nest the SUMIFS withing VLookUp, but I am not sure as to why it won't work.
I'm providing you with two possible solutions.
1) The first one uses the SUMPRODUCT function. You may not have seen this kind of notation before.
When ranges are multiplied by each other like so (B3:B8=G3)*(C3:C8=G4) they are actually turned into boolean arguments. If you highlighted this part of the code and pressed F9 it would look like this: {0;0;0;0;1;0;0}. This is an array where TRUE for both criteria meet. So our Branch is "A" and our Carrier is "F". In the rest of the cases either or both are false resulting in zeroes.
Now if you multiply this array by the range with account numbers, obviously the only number remaining will be the one multiplied by 1 and so you have the answer however keep in mind that as you are multiplying if the account is not a number the function will fail!
2) This is why we have a second method using =INDEX() and =MATCH() functions.
To overly simplify this - the INDEX function grabs contents from an array at a specified position (row and column), while the MATCH function gets the position of an item in an array.
The idea with using ranges as multiple criteria is the same as in the first example, however this time when we get our array of zeroes and ones {0;0;0;0;1;0;0} we use the match function to find at which position our criteria cross (as seen on the screenshot it's the 5th position, as it's in the 5th row of the entire column D, the match function searches the {0;0;0;0;1;0;0} array for a 1 and returns its position in the array) and so this is our ROW.
Knowing the position of the contents we searched for we use the INDEX function to grab the contents of the cell in that position so =INDEX(D2:D8,MATCH(1, INDEX((B2:B8=G3)*(C2:C8=G4),0),0)) is actually =INDEX(D2:D8, 5) meaning that the INDEX function grabs contents of the 5th row from the range D2:D8 which is cell D6.
The green boxes are just there to show the instance where both of our criteria are met (cross).
Please try this formula.
=INDEX(Table1[Account],SUMPRODUCT((Table1[Branch]=F$3)*(Table1[Carrier]=F$4)*ROW(Table1[Account]))-1)
Note that you may have to adjust the final -1. This is because the indexed table starts in row #2 and the SUMPRODUCT function returns a sheet row number. If your table would start in a different row the difference between the sheet row and table row would be larger. It must be adjusted here. Or you might work with sheet references (named ranges) and require no adjustment at all.

Resources