How to inverse vlookup in Google Spreadsheet? - spreadsheet

I have a table with key values pairs, keys in A and values in B:
A B
+-------
1 | a x
2 | b y
3 | c z
Getting the value for a key can be done with the vlookup function:
=VLOOKUP("a";A1:B3;2;FALSE)
But how to perform the inverse lookup? How to get the key for a value?
This is an example.
Update: I added Wolfs answer.

Given your example, try the following:
=index(A:A,match(C1,B:B,0))
It was found on the Google product forums.

This blog post by Ben Collins has an answer that exactly fits what you need. Basically, you can force the equation to read the range backwards and believe your right column is the first one, and your left column is the second one.
This is what your formula would look like:
=VLOOKUP("a";{B$1:B$3, A$1:A$3};2;FALSE)
Blog post with more detail here.

Vlookup is a lookup function which, like an Excel's INDEX-MATCH, searches for a value in the leftmost column of one tabel and then retrieves information from a column to its right. In contrast to INDEX-MATCH excel function, VLOOKUP offers more control over the retrieved information by specifying on what should happen when it doesn't find the key sought - return nothing (the default), insert new data found below or above as defined by another search term, or just simply enter a "zero" value when searching for positive number
Answer:
Inverse Vlookup Tableau function
Equal to = Tableau("vlookup", "row of column A you want lookup from", "column/Sheet with values that go into table")
Almost equal to -1 * Tableau("vlookup"...) = TRUE.
It's important to have the correct formulas and syntax to get your desired results, hence why this function is called an "Inverse Vlookup".
Here is a helpful article about Excel Vlookups to read before you get started

Related

Multiple substitue or replace text in excel using a table

I'd like to create a super substitute function in excel (if there is such a thing). For my needs, nesting is insufficient because my substitution list is long.
What I'd like to do is have a named table with two columns for the function to use as a look-up for potential substitutions. The first column would contain the original text and the second would contain the replacement text.
If we look at the above example, the columns R and S consists of my table, with column R as the original text that I wanted replaced with the equivalent row entry in column S, if found in my list. My data in column V is the list that I want to work on. I want the formula in column W to look at the equivalent entry in column V and lookup in the table for any matches within the text. If there is a match, then I want that text from column R replaced with the text in column S. In some cases there can be 2 matches, as with the top example of 'LHR:JFK' which should ideally get replaced to 'LON:NYC'.
There are ways to do this with VBA but I would like to know if there is an Excel formula option for the same as I don't know where to begin with VBA.
Your help is greatly appreciated.
Thanks,
Neha
This will do as you ask:
=SUBSTITUTE(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3),IFERROR(VLOOKUP(RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3),R:S,2,FALSE),RIGHT(SUBSTITUTE(V2,LEFT(V2,3),IFERROR(VLOOKUP(LEFT(V2,3),R:S,2,FALSE),LEFT(V2,3))),3)))

Excel formula not working as expected

I have a sheet that shows max values spent anywhere. So I need to find most expensive place and return it's name. Like this:
Whole sheet.
Function.
Function in text:
=IFS((A6=MAX(D2:D31)),(INDEX(C2:C31,MATCH(A6,D2:D31,0))),(A6=MAX(H2:H31)),(INDEX(G2:G31,MATCH(A6,H2:H31,0))),(A6=MAX(K2:K31)),(INDEX(K2:K31,MATCH(A6,L2:L31,0))))
Basically I need to find a word left to value, matching A6 cell.
Thanks in advance.
Ok.. Overcomplicated!
Firstly, why the three rows? it's a lot easier if you just have one long row with all the data (tell me if you actually need 3 I'll change my solution)
=LOOKUP(MAX(D2:D31);D2:D31;C2:C31)
The MAX formula will lookup the biggest value in the list, the Lookup formula will then match it to the name.
Please note: If more than one object has the maximum price, it will only return the first one. The only way I can think of to bypass that would be to build a macro.
EDIT:
Alright.. Multi Column solution is ugly and requires extra columns that you can just hide.
As you can see you'll need 2 new columns that will find the highest for each row, 2 new columns that will find the value for each of these "highest" (in this case tree and blueberries) and then your visible answer will simply be an if statement finding out which one is bigger and giving the final verdict. This can be expanded with an infinite number of columns but increases complexity.
Here are the formulas:
MAX(H2:H31)
LOOKUP(A5;H2:H31;G2:G31)
MAX(L2:L31)
LOOKUP(C5;L2:L6;K2:K6)
IF(A5>C5;B5;D5)

Query several ranges and add automatically a column to know the source of each row

I am trying to achieve the following in Google Spreadsheets.
First, I want to query several ranges (in different sheets from the same spreadsheet). I tried a formula like this =query(arrayformula({indirect(E2:E10)}),"select * where Col1 <>''") with no success
In E2:E10 I have a list of ranges. Column F contains a name that describes the source of the value in Column E.
My second problem is that I need to add a column to the output of that query that tells me the origin of each row.
If the sources are ranges of 3 columns by country I need to merge those tables and add that country to each row.
All credits to +Ben Liebrand who helped me out here: https://support.google.com/docs/profile/3464
"I just want to start of by saying that the indirect() function does not work in an arrayformula() function as expected. So you will need to take another approach. I can understand what you are trying to do so I added another TAB in your spreadsheet to demonstrate another approach. I know it was initially a specific design you were trying so I made some changes to what you had. Maybe you can take a look at what I have offered and maybe you can tweak your design.
I know what I am offering is just very rough but you will also notice that I removed the end row specifier from your ranges in the range table.
Don't assume my example to be the final result but I was just trying to show that the range you were trying to use with the indirect() function will not work.
So hopefully this will give you a new idea of how you can maybe handle this.
My formula also adds the country to each of the tables in the output. My formula looks like this
=query(ArrayFormula({
if(len(indirect(regexextract(F2,"\w+\!\w+")&":A")),G2,),indirect(F2);
if(len(indirect(regexextract(F3,"\w+\!\w+")&":A")),G3,),indirect(F3);
if(len(indirect(regexextract(F4,"\w+\!\w+")&":A")),G4,),indirect(F4);
if(len(indirect(regexextract(F5,"\w+\!\w+")&":A")),G5,),indirect(F5);
if(len(indirect(regexextract(F6,"\w+\!\w+")&":A")),G6,),indirect(F6);
if(len(indirect(regexextract(F7,"\w+\!\w+")&":A")),G7,),indirect(F7)
})," select * where Col1 <> '' ")
Hope this is of some help to you"
And I hope is useful to the community
GerĂ³nimo

Search and find in VBA

I need help for writing a macro to use in Excel. Essentially what I'm working with is large groups of financial data that are almost always unique. I need to be able to compare each cell in one column (B) to another entire column (H) to search for a matching value. After finding the matching value, I need the macro to print the value related to the original found value into the cell next to the searched value. (Column G will have titles referring to the value of cell H)
Basically I need to be able to compare the individual value of each cell in column B to the entire column H, and if and when there is a match, have the value of column G appear in column A next to the original cell in column B. Sorry for the terrible explanation.
Search Column H for value match of B2. If H30 = B30, print G30 in A2.
Since you can't use VLOOKUP(), you'll need to use a nested MATCH() and INDEX().
=INDEX(G:G,MATCH(B1,H:H,FALSE))
For reference:
INDEX()
MATCH()
Searching
You most likely do not need a macro for this. Try the VLOOKUP function: https://support.office.com/en-in/article/VLOOKUP-function-adceda66-30de-4f26-923b-7257939faa65
Edit:
Syntax should be something like:
=VLOOKUP(B1, G:H, 2, FALSE)
then fill down and adjust absolute references as appropriate for your spreadsheet.

To find if a cell value is present in other column using excel macro

In excel, column A contains the list of words and column B contains its respective synonym. Sheet2 has a list of words in column A.
I want to see if the words present in column A of Sheet2 has any of the words present in column A or Column B of Sheet1. If yes, I would like to have the result in Sheet1 in front of corresponding word in column C
Word synonym
abandonment desertion
abandonment leaving behind
abandonment leaving
abandonment rejection
abandonment neglect
abase lower
abase demean
abase degrade
abase belittle
Final result required:
Loan mortgage mortgage here morgage is returned from Sheet2.
Have a look at the find-method to see if the word exists in sheet1: http://msdn.microsoft.com/en-us/library/office/ff839746%28v=office.15%29.aspx
Have you ever written any VBA? I found OZGrid a good source to learn. Chapter 2 covers the find-method already: http://www.ozgrid.com/Excel/free-training/ExcelVBA1/excelvba1lesson2.htm
Or can you be more specific about the problem you are facing?
Edit: don't have enough reputation to comment...
Did you consider using "vlookup" instead of macro? Below vlookup function will do the work I guess. In this function, excel is looking for the value in A1 cell within sheet2>A column and return a result if it can find it. If it can not find it, then it looks for the value in sheet1>B1. You can simply drag the formula.
=IFERROR(VLOOKUP(A1,Sheet2!A:A,1,FALSE),VLOOKUP(Sheet1!B1,Sheet2!A:A,1,FALSE))