VLOOKUP on all sheets - excel

I have a "Master" sheet with part numbers in column A and locations in column B. I have approx 200 sheets with just part numbers in column A. How can I apply VLOOKUP to all sheets so every part number on every sheet will have my location in column B? It will take forever to do it manually. Thanks

Here is one way to achieve a lookup of data from the Master Sheet, assuming the starting cell containing your lookup value is A2. This also assumes that all sheets are in the same workbook:
=VLOOKUP(A2,Master!$A$2:$B$11,2)
An explanation of what each argument does from left to right:
A2 - cell containing lookup value in one of the 200 sheets. (This can be any cell which contains a lookup value).
Master is the name of the sheet which contains the data to look up.
$A$2 is the top left cell for the table data to look up in the Master sheet, we want to use $ sign because the lookup table top left cell should be fixed.
$B$11 is the bottom right cell for the table to look up in the Master sheet, we want to use $ sign because the lookup table bottom right cell should be fixed.
2, this is the column index which includes value you want returned for a successful look up. The column index starts at 1 and increases to the right, The column at index 1 contains the lookup values. In your scenario, index 1 is Column A and specifying an index of 2 will index column B
To deal with blank cells or cells which are not found in the table you can extend this formula like so:
=IF(ISNA(VLOOKUP(A2,Master!$A$2:$B$11,2)),"",VLOOKUP(A2,Master!$A$2:$B$11,2))
This formula will do the lookup, if it does not find the value it is looking for it will leave the cell blank, otherwise it populates the cell with the found data.
You can now copy and paste to cell A2 (or replace A2 with starting cell) and then drag the formula down the column to the last cell that requires VLOOKUP from the data table in the Master sheet. For every row X, it will update the lookup return data for the corresponding lookup value.
You will need to copy the formula then drag it to fill the entire B column for each 200 sheets which is a bit tedious. An alternative is to write a macro which loops over each sheet in the workbook and populates the corresponding column with the result of the lookup from the Master sheet.
VLOOKUP works when the lookup value is in some column X and the value to return, the data, is to the right of X.
If the data to be returned is to the left of the lookup value, you must use a combination of MATCH and INDEX which is slightly more complicated.
To lookup data in a different workbook, you will need to create a link between the two workbooks, this article explains how to do so.

Think about changing all your data to a single sheet. You may try this home made function:
Function AllSheetVLookup(ByVal lookup_value, ByVal search_col As Long, ByVal return_col As Long, Optional book_rng As Range)
Dim ws As Worksheet, r As Long
On Error Resume Next
For Each ws In IIf(book_rng Is Nothing, Application.Caller, book_rng).Worksheet.Parent.Worksheets
r = Application.WorksheetFunction.Match(lookup_value, ws.Columns(search_col), 0)
If r Then AllSheetVLookup = ws.Cells(r, return_col): Exit Function
Next
AllSheetVLookup = CVErr(2042) 'Not found, #N/A! returned
End Function
lookup_value - value to search, has in VLOOKUP;
search_col - column number in worksheets where to search for value
return_col - column number to return value from matched with match
book_rng - optional. Cell in another book if another book is to be searched. If ommited, book where function is called is used.
Example:
=AllSheetVLookup("part_number", 1, 2)
Will search for value "part_number" in column A (1st) from all worksheets of current book, and return value of column B (2nd).

Related

Excel: Increment column letter

I have an excel workbook with two worksheets.
On one sheet I have data horizontal and my second sheet I have data vertical.
I want on sheet 2 to drag down my reference from sheet 1 data.
I am looking to have column increase not my row increase? Makes sense?
I try to "equal" the cell i want from sheet 1. However when I drag down my reference goes down instead of across.
Any help would be appreciated.
Conceptually: Use Index. The syntax is Index(range,row number, column number)
If you want to transpose a range in Sheet1 to Sheet2, you can use
=Index(Sheet1!$A$1:$J$10,column(A1),row(A1))
Copy across and down.
See how the row argument uses the column command and the column argument uses the row command. That means in the starting cell A1, the INDEX formula will return the column number 1 for the row argument and the row 1 for the column argument, i.e.
=Index(Sheet1!$A$1:$J$10,1,1)
Copy the formula to row 2 and the reference in the column argument will refer to Row(A2), so the formula will translate to
=Index(Sheet1!$A$1:$J$10,1,2)
i.e. it will return the value from the second COLUMN of the index range. See the screenshot for a result. Change the Index range to your desired source.

Return a value from another column and sheet using MATCH

I have a worksheet where I need to fill in data referenced from other worksheets.
I need to match a value on my main sheet with one on another sheet and once the cell has been found I need to get the value of a different cell offset by 1 row up and 5 columns left. I know which columns I need but I need MATCH to return the initial row.
MATCH will give me the initial row that I need.
ADDRESS means I can build the cell reference.
OFFSET allows me to reference another cell if I have the original cell address.
However the ADDRESS function will only return the address as a text string and not as a reference that can be used in the OFFSET formula.
Does anyone know of a way to make this work?
Kind regards
Matt
If the value on your main sheet is in cell Sheet1!A1, and the matching value is somewhere in column Sheet2!J:J.
The MATCH formula will return the row number:
=MATCH($A$1,Sheet2!$J:$J,0)
You want one row up from this so the formula will be:
=MATCH($A$1,Sheet2!$J:$J,0)-1
Make sure this does not fall below 1
To return a reference to another cell you'd use INDEX as this is non-volatile and won't try and recalculate unless you change a figure it uses.
It returns a reference to a cell given a range of cells, a row number and a column number.
Your column is always five columns to the left, so if you're matching in column J you want a figure from column E.
e.g. If you want row 5 from column E you'd use =INDEX($E:$E,5).
Replace the row number with your Match formula and you get the figure you're after:
=INDEX($E:$E,MATCH($A$1,Sheet2!$J:$J,0)-1)

Creating dynamic hyperlinks with VLookup using excel

I've searched for a solution for this issue I'm having but I haven't been able to find anything.
Let's say I'm working out of 2 worksheets, A and B.
Worksheet B has a cell I'll call Price. Price depends on a certain input, which comes from the AJ column in worksheet A. Price gets a dollar value from column BW inside of worksheet A.
Worksheet A has a column (AJ) and a column (BW).
My question is this. How can I click on the cell in worksheet B (Price) and be redirected or "hyperlinked" to the appropriate cell in Worksheet A column BW?
You can place formulas within the hyperlink function
=HYPERLINK("[book1]SheetA!BW" & MATCH(C3,AJ:AJ,0),INDEX(BW:BW,MATCH(C3,AJ:AJ,0)))
In the above
Hyperlink is the main function
"[book1]SheetA!BW" - you would change to your workbook name. this is telling it which sheet and column to link to
MATCH(C3,AJ:AJ,0) - This looks for your input value in column AJ and returns a number, that number is the row number. you will need to select the whole column or the match rows wont line up with the real row numbers
c3 would be the input for your vlookup, or (index match which is what I used)
INDEX(BW:BW,MATCH(C3,AJ:AJ,0))) this is an index match that returns the value of BW you looked up into the price cell on sheet B. It will show as the text

How do I automatically update cells to match values from another sheet when one cell is changed using data validation?

I have a list of items on Sheet 1 with the names of each item in column A and then further information in the subsequent 5 columns.
On Sheet 2, in each of the cells of column A, I have set it so that I can pick any item from a dropdown list using data validation. I want the subsequent cells in the row to automatically assume the value of the respective cells in Sheet 1.
So if in Sheet 2, Cell A1 I select Item 3 (which is in Cell A3 on Sheet one), I want Cell B1 on Sheet 2 to have the same value as Cell B3 on Sheet 1.
I could get the result I wanted by using =IF($A3='Sheet1'!A3,'Sheet1'!B3,) and then adding each possible item but that seems really long winded and would require adding to the formula every time I added an item.
Any idea if there is a way of doing this? Sorry if my explanation is a bit confusing. My excel knowledge is not great!!
Thanks in advance
Use the Vlookup function
Next to your data validation cell, enter (assuming the first sheet called Sheet1):
=Vlookup(a1,Sheet1!a:f,2,0)
This will return the data that match for the 2nd column. For the 3rd use:
=Vlookup(a1,Sheet1!a:f,3,0)
And so on..

Transpose column on one sheet to row on another, with linking

I have a column of data in say A1:A10 in worksheet A. In worksheet B I have a range for data from A1:J1. I need the data from the column in worksheet A to be transposed into the data range in worksheet B. I can Paste Special and paste in the values but I need the information in worksheet A to update automatically that in worksheet B.
Any help or advice is appreciated.
Please select A1:J1 in worksheet B and enter:
=TRANSPOSE('worksheet A'!A1:A10)
with Ctrl+Shift+Enter.
Copy this:
=INDEX(A!$A$1:$A$10, COLUMN())
into your cells A1 through J1 in worksheet B (so that all cells contain the exact same formula).
Basically, the INDEX function grabs a specified element out of your vertical array A1:A10 in worksheet A (the worksheet name is specified before the exclamation point). Which element to choose is given by the second parameter. Here, we simply use the COLUMN() function, which returns 1 for column A, 2 for column B and so forth...
EDIT:
If you want to use a different data column as the source of your data, simply replace the A!$A$1:$A$10 with anything else you like, e.g. Sheet3!$C$10:$C$23.
To place the copied data somewhere differently, copy the formula above into all the target cells, wherever they may be. BUT: If the target cells do not start in column A, you need to subtract an offset from the number returned by COLUMN(), so that you pick element 1 in your first target cell. So, for example if you want to place the data into cells J5 through S5, you will need to copy this formula into each cell:
=INDEX(A!$A$1:$A$10, COLUMN() - 9)
This is because COLUMN() returns 10 for column J, but you want that cell to contain element 1 of your source data column, so we subtract 9 to get from 10 to 1. In column K, COLUMN() will return 11, subtracting 9 yields 2, so INDEX(...) will then return the second data element for that cell, and so on.

Resources