Excel search and return - excel

So, I have an Excel-file with two sheets. The first sheet contains 7 Columns of different values.
The second sheet contains a list of special customer prices.
What i want to do, is basicly search for the value given in e.g. cell A2, in Sheet2!A:A. If i were to find this value (it's a text value), I want to return the value located in that spesific row containing the value searched for, only 3 colums to the right.
I've done a lot of experiments, but really can't get INDEX and MATCH to do the work properly for me. Anyh suggestions?
Feel free to ask for more information, as I know I can be a challange to understand..
Best regards

try offset() and match(), offset(reference,rows,cols). use match to find the number of rows or columns to move from the reference point.

Using OFFSET is against almost all best practice guides. It is a volatile function, meaning it should be avoided at all costs. Use INDEX+MATCH instead. It can do all the same stuff but has much better performance.
=INDEX(column holding the value you want to return, match to find row #, 1)
=MATCH(value you are looking for, column you are searching in, 0 means exact match)
Result:
=INDEX(Sheet2!$D$2:$D$10,MATCH(A2,Sheet2!$A$2:$A$10,0),1)

I believe the function you are looking for is a vlookup. Try this:
=vlookup(A2, Sheet2!A:D, 4, 0)
Regards,
Windyvation

Related

VLOOKUP Multiple Columns If Not Found In First Column

I have a long list of part numbers where I need to be able to lookup and retrieve information on them.
These parts can have several alternative part numbers. I have figured out how to get the data returned if my data table only shows one of the possibly part numbers.
The issue is that I want it to be able to look up the columns to find a matching value.
As in the picture below for example. 5-E26 is the equivalent to E5-25. So if I input 5-E26 in the cell, I want it to continue searching to find the value in B7, and return the data as done A4 and A5.
Is this possible to do with Vlookup? Or is there a smarter method for it?
I struggle to fully understand how your data works but here is a possibility:
So the translated version of the formula I used in G2:
=INDEX($D$1:$D$5,AGGREGATE(15,3,((($A$2:$D$5=F2)/($A$2:$D$5=F2))*ROW($A$2:$A$5)),1))
You could also try (in my case):
=INDEX($D$1:$D$5,SUMPRODUCT(($A$2:$D$5=F2)*ROW($A$2:$D$5)))

Can these formulas be simplified? Why does INDIRECT function seem to not work inside an ISBLANK test within a MATCH formula?

Summary
I need an array formula that takes a row of data of certain length from Sheet1. For that row, in each column that is not blank, I need to grab the Sheet1 header value for that column and display that data in a continuous row on Sheet2 (without any spaces in between the row's cells).
Background
I have a table of data (employees and industry certifications with expiration date being the table's cell data) on sheet 1, with a row for each employee the spreadsheet is tracking. The certifications are the columns.
We are using this information to link to ID Badge Printer software (Bodno Silver), where we are limited to linking columns of data to a particular textbox.
The problem lies in the fact that not everyone has every certification. The rows are peppered with blanks separating the certifications that each employee does have. While setting up the required text boxes in the badge software template, that each link to a specific column, I quickly realized that since not everyone has every certification if we used the data how it was we would have a bunch of strange looking blanks in between the listed certifications rather than a continuous list.
What I did
My solution to this (which I'm open to a better one if anyone knows of one, other than "use better software"), was to create a new sheet and array formulas that no one would use except for me and the id printer software. This sheet would have a similar data table that took the rows of data interspersed with blank cells between expiration dates, and put the matching column headers for cells that had a date in them into a continuous row of the same maximum length (eliminating the blank cells).
Essentially, this would allow me to circumvent the restrictions of the badge software and each textbox would be MatchedCert1, MatchedCert2, MatchedCert3, etc. up to the original maximum number of certifications.
Pictures are probably better than my words at explaining what I am going for:
Sheet1 (source)
Sheet2 (result)
The array formulas
I worked on this one for a while. What I thought would be a simple INDEX, MATCH, ISBLANK formula (that I could create using the appropriate relative and absolute cell linking) and then expand to the whole sheet turned into a witch hunt and me praying for forgiveness for my sins to all that may be holy. Also a lot of googling.... I realized quickly that this one may not be so simple after all.
Finally, I arrived at the following two array formulas in order to correctly show what I was going for:
First Column of training section
{=IFERROR(INDEX(Sheet1!$E$2:$P3,1,MATCH(FALSE,ISBLANK(Sheet1!E3:Q3),0)),"")}
(easy enough, right? I thought so...)
I felt good about this until I tried to think through what would be required to get the formula to be universal so that I could use it on the entire table.
I feel dirty just putting the following in public, but here goes...
Second column through last column array formula
{=IFNA(INDEX(INDIRECT(ADDRESS(ROW($E$2),(MATCH(E3,Sheet1!$2:$2,0)+1),1,1, "Sheet1")&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),1,MATCH(FALSE, ISBLANK(INDEX(INDIRECT("Sheet1!"&ADDRESS(ROW(E3),(MATCH(E3,Sheet1!$2:$2,0)+1),1)&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),0,0)), 0)),"")}
(please don't call the police...)
[ninja edit] While this array formula works for 2nd result column through the final column, it doesn't work if there's not a blank column following the result range. The actual spreadsheet has 4 different groups of certifications that run horizontally, but I was able to just add a blank column in the corresponding data from the other sheet easily enough, so I just let it go. I'd give somebody a nickle for the answer to why that's the case here too [/edit]
Results
The first array formula, and INDEX MATCH using ISBLANK is rather straightforward.
The biggest question for me here, and the thing that drove me absolutely nuts for a couple of days, is why the second array formula requires the additional INDEX function nested inside of the ISBLANK function.
While taking the function apart and experimenting I realized that if I have any INDIRECT reference inside a ISBLANK function, which is itself inside of a MATCH function, the result of the match was ALWAYS 1:
{=MATCH(FALSE,ISBLANK(INDIRECT("$E3:$Q3")), 0)}
The above ALWAYS returns 1, whereas if I put the range in explicitly, the function would work just fine. That wasn't an option for me, since I needed to dynamically return the starting position for the match using the previous cell's address.
However, adding an INDEX function (with a column and row value of 0) to encapsulate the INDIRECT function provides the correct answer. I figured this out just by trial and error.
Questions
Can someone with more knowledge please let me know what is causing this behavior?
As a broader question, given I am limited to using formulas (no VBA), I would also like to know if I'm going about this in the wrong way or if there is a much simpler way of accomplishing this without this behemoth of a formula?
I know this sheet will probably require maintenance in a year - good luck future self!
Put this in E3, Copy over and down
=IFERROR(INDEX(Sheet1!$2:$2,AGGREGATE(15,6,COLUMN(INDEX($E:$P,MATCH($C3,Sheet1!$C:$C,0),0))/(INDEX(Sheet1!$E:$P,MATCH($C3,Sheet1!$C:$C,0),0)<>""),COLUMN(A:A))),"")
As to why your formula is not working, it is too convoluted to parse. One note, unless the sheets is the variable, one should avoid INDIRECT as much as possible. INDEX can almost always be used in its place.
Both INDIRECT and ADDRESS are volatile functions. Volatile functions will re-calculate every time Excel re-calculates, leading to a lot of unnecessary computations.
Not a solution but to answer why you are seeing this behavior:
EDIT: PREVIOUS EXPLANATION WAS JUST PLAIN WRONG
This confused me so, I did a bit of investigation:
I think that your problem is actually coming from the ISBLANK function because it is intended to be used with single values, and cannot handle ranges. Any BLANKs which are returned by functions are only converted to numeric values (0), when the BLANK is returned to (or displayed on) the sheet. If the function is returning to another function, the BLANK value seems to be preserved.
EDIT: ADDING A SOLUTION WITHOUT ARRAY FORMULAS
This is probably more complex than using an array formula... but I strongly dislike them, so do all I can to remove them.
Firstly, I would add an index to your positions in the results sheet:
=IF(F$7>COUNTIFS($F3:$L3,"<>"),
"",
IF(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
)=0,
"",
INDEX(
$F$2:$L$2,
MATCH(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
),
$F$7:$L$7,
0
)
)
)
)
Basically, the formula looks at the cert in the previous cell, and looks for the next, minimum index, greater than that.

Match and lookup to find price

I would be grateful if someone could help with the following.
I have a workbook (called passenger car comparison) that has a column of postcodes (B1) and then columns for different prices (C1:I1).
In a separate workbook (called Search Tool), I would like to display the post codes from B1 as a dropdown list, with the same row also displaying the prices from C1:I1 for that particular post code.
Would I need to use INDEX and MATCH or HLOOKUP? Confused!
There is a link to the spreadsheet here if my explanation isn't clear!
Many thanks in advance!
You can actually use both.
However, you should use VLOOKUP instead of HLOOKUP, because your data elements are in rows, not columns. This is the most direct approach (=VLOOKUP(DropDown,WholeTableFromBtoI,Line,FALSE) - the FALSE here avoids linear interpolation with your postcodes). You can get your line from the row 1 of both cells, using MATCH, if you want to get fancy, by =MATCH(Category,FirstLineOfTable,0).
And, If you intend to use MATCH straightforwardly, your better approach would be using OFFSET as well, as in =OFFSET(FirstCellOfTable,MATCH(PostCode,PostCodeRow,0),MATCH(Category,FirstLineOfTable,0). It's a probably not the most intuitive approach, but it works as well.
Hope that helps.

Using CountIf in excel with row() as the 2nd range

Is it possible to have a function in Excel where the second range is the current row the user is current at? For example, if column A has customer numbers then can a user have column B be the current count of rows that have the same customer number? Something like =countif(A1:Row(), Row()). So, if the user were on B14 then the function would be =countif(A1:A14, A14).
I'd rather not use VBA and I'm new to functions in Excel. My apologies if it's a simple answer. I swear that I did search for an answer before firing off this question.
The answer to your question is yes. Use INDIRECT function. Something like:
=COUNTIF(INDIRECT("A1:A"&Row()), INDIRECT("A"&Row()))
You could use something else rather than taking the current row you could have a drop-down list with all the ids. The cell remains the same but you will be able to select the number that you want from the list and use it to count.
Have a look here and tell me if you need more help:
http://www.techrepublic.com/blog/microsoft-office/how-to-add-a-drop-down-list-to-an-excel-cell/
Another approach:
=COUNTIF(OFFSET($A$1,0,0,ROW()),A:A)
Better than using the "fully" volatile OFFSET and INDIRECT set-ups is to use one with INDEX, which, in this construction, is merely volatile "at workbook open".
Also, if you are looking for a formula which can be copied to other cells such that the row referenced is always that in which the formula resides, it is much better to use a construction with ROWS rather than ROW, since the latter is affected by row insertions within the range whereas the former is not. Hence, the formula placed in row 14 would be:
=COUNTIF(A1:INDEX(A:A,ROWS($1:14)),INDEX(A:A,ROWS($1:14)))
Regards

Excel, Specifying cell contents as a result of other cells

I don't use excel often, and I haven't really found a good solution to my problem. (which is probably really simple).
I would like to have a cell with a function in my spreadsheet that shows another cell value value that depends on yet another cell value.
Such as:
The Best Deal heading simply uses the formula
=MAX(D3,D1000)
But under Best Deal I would like to display the Name Test1 rather than the numeric value.
Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))
Obviously that function wouldn't work as I wrote it, but hopefully this pseudo code gives you an idea of what I mean. The purpose is that if more entries are added, it would be able to handle them.
I know this is possible, but I'm having some trouble. Hopefully I can get some help here.
Thanks!
The easiest way to do this is to use a combination of Index and Match. Match will find the position of the maximum value, and then Index will look in column A and return the data in that same position. So, your formula would be:
=INDEX(A$3:A$1000,MATCH(MAX(D$3:D$1000),D$3:D$1000,0))
Put that formula in F3. No hidden columns required.
Sorry, I missed the part about the expanding range. You can do that by using Count or CountA along with Offset. The new formula would be:
=INDEX(A3:OFFSET(A3,COUNTA(A:A)-1,0),MATCH(MAX(D3:OFFSET(D3,COUNT(D:D)-1,0)),D3:OFFSET(D3,COUNT(D:D)-1,0),0))
More complex, but it is basically the same except that it will expand as you add new values at the end.
There is only one 'simple' way I can think of this, but it requires hidden columns (sorry).
set E1 = A1 and fill down all the way (Basically you are making a copy of column A in column E but you are using a formula so it will always be the same)
Then under 'Best deal' - put this formula:
=VLOOKUP(MAX(D3,D1000),$D:$E,2,FALSE)
Then hide column E so it doesn't look like a mess. This way you do not need any fancy macro's and it will work everywhere because it is a normal formula.
"Another thing that would be nice to know, is if there is a way to know the maximum row with data in it. So rather than =MAX(D3,D1000) something like =MAX(D3,Max(RowCount_InD))"
This is a called a dynamic named range. Create a name for the ratio data, and set up the formula for the name range to be this:
=OFFSET($D$3, 0, 0, COUNTA($D$3:$D$1048576), 1)
More info here: http://www.ozgrid.com/Excel/DynamicRanges.htm
Then, assuming you name this named range ratio_data, your function could be referring to =MAX(ratio_data) in combination with index-match as suggested by #Tim Mayes. The range will expand automatically as you add more data.
=INDEX(A$3:A$1000,MATCH(MAX(ratio_data),ratio_data,0))
Ideally, you can replace the A3:A1000 by a dynamic named range as well.

Resources