Excel - Find matching values and copy different cell - excel

I have 2 Excel spreadsheets and both sheets have a "Code" field and value that may or may not exist in both. In sheet1 and sheet2 there is also an "ID", i'm hoping that if the "ID" is populated in sheet1 and if the matching code exists in sheet2, a query can transfer the "ID" to sheet 2
SHEET1
|
SHEET2
I can find the matching values using vlookup but my issue is getting the ID field to populate
=VLOOKUP(A1,Sheet1!A:A,1,FALSE)

Instead: =VLOOKUP(A1,Sheet1!A:B,2,FALSE).
From Microsoft's help on Vlookup:
How to get started
There are four pieces of information that you will need in order to build the VLOOKUP syntax:
The value you want to look up, also called the lookup value.
The range where the lookup value is located. Remember that the
lookup value should always be in the first column in the range for
VLOOKUP to work correctly. For example, if your lookup value is in
cell C2 then your range should start with C.
The column number in the range that contains the return value. For
example, if you specify B2:D11 as the range, you should count B as
the first column, C as the second, and so on.
Optionally, you can specify TRUE if you want an approximate match or
FALSE if you want an exact match of the return value. If you don't
specify anything, the default value will always be TRUE or
approximate match.
Pay special attention to parameters 2 and 3.
Note that number 2 "The range where the lookup value is located" should be the full range where the first column of the range has the values to lookup and the last column of the range should contain the values you want to return. So your A:A only having one column, will only lookup and return values in column A. You want values returned from column B so it must be included as well, to become A:B.
Since column B is the second column in the lookup range of A:B then your third parameter will be 2 which leads to the vlookup at the top of this answer.

This is what you are doing:
VLOOKUP(A1,Sheet1!A:A,1,FALSE)
(I will only talk about Sheet1!A:A and 1)
You are looking into column A and from there you are taking column number 1 (which is column A).
What you should be doing, this this:
VLOOKUP(A1,Sheet1!A:B,2,FALSE)
Look into table, made up of columns A and (up to) B, you will automatically look into the first column, and you return the value you find in column number 2 (which is column B).

Related

Excel: Compare and replace across sheets

I have two spreadsheets. I need to compare and replace based on the other values.
So on sheet1 I need it to replace Column A with column C from Sheet2 if column A sheet1=Bsheet2.
Example
Column A Sheet1
Row1 = Steve
Column B Sheet2
Row4 = Steve
Column C Sheet2
Row4 = Bill
I need it to replace Column A Sheet1 Row1 "steve" with "Bill"
So if the two columns have a similar value it replaces it with the same row from column C on the second sheet.
Clear as mud.
I think you are looking for VLOOKUP.
Use VLOOKUP when you need to find things in a table or a range by row. For example, look up a price of an automotive part by the part number, or find an employee name based on their employee ID.
In its simplest form, the VLOOKUP function says:
=VLOOKUP(What you want to look up, where you want to look for it, the column number in the range containing the value to return, return an Approximate or Exact match – indicated as 1/TRUE, or 0/FALSE).
Create a new column (mapped) and use VLOOKUP to populate it based on the value in Column A:
=VLOOKUP(A1, Sheet2!$C$1:$D$10, 2, FALSE)
Left to right:
A1: This is the search value (steve in your example).
Sheet2!$B$1:$C$10: This is the search range. Adjust this as you see fit. Make sure to keep the absolute $ references in there as we do not want the search range to change as we move down the search values.
2: If a match is found in the first column of the search range, return the value in the second column.
FALSE: Require an exact match. Change this to TRUE to return the closest match. If this is TRUE then the data in sheet2!B:B should be sorted.
You can copy this down in column mapped to each row as needed. Once populated you could:
Hide the 'search value' column, leaving only mapped.
Create another sheet, and inject the data from mapped using =sheet1:B1
Copy the data out from mapped, then paste it over using paste special / paste values, which will discard the formulae and leave you with just the results.

How can I reference values dynamically from 3 columns in another sheet based on a value in cell?

I have a dropdown list of 104 values in column F. I want if any of the values is selected from that list cloumn, a corresponding value should be referenced from sheet and be inserted the cell in Column i .
If a value is selected in sheet 1 column F then it should match it with a similar value in sheet 2 columnA and also select the value corresponding value in Sheet 2 column B and go back and insert it in sheet 1 Column i.
Please note that each of the 104 values in column F has its corresponding value from a cell address of another worksheet
worksheet with dropdown list column F and inserted value column I
worksheet with referenced value
use Index/Match
=Index("select the data that you want displayed",match("common data", "common data",0))
I use this a ton when pulling data from multiple tabs.
=index(List of Customers,match(tab1_CustomerID, tab2_CustomerID,0))
hope this helps!
That calls the use of two possible functions:
The first is VLOOKUP, which you can find about in here:
https://exceljet.net/excel-functions/excel-vlookup-function
(please note the 4th parameter!!!!)
The second combination is index/match, which I think is more appropriate for your situation:
https://www.ablebits.com/office-addins-blog/2014/08/13/excel-index-match-function-vlookup/
Or here:
https://exceljet.net/index-and-match
Less theoretical but with the best explanation:
http://www.randomwok.com/excel/how-to-use-index-match/
more complicated but fits your purpose better
Index/match with more than one column to match against:
https://www.deskbright.com/excel/index-match-multiple-criteria/

Excel if Function,select cell in line with match

Here is my problem .
I have an excel workbook with 2 sheets with the same fields but different amount of records. Both sheets have an ID field and date field.
If the ID from column a of sheet 2 exists in column a of sheet 1 then I want to use the date field from sheet 2 to populate the date field in sheet 1 for that matching ID.
Please help me figure this out. I can post sample data.
Thank you
As suggested by #L42 VLOOKUP can be used for your situation. A simple example mentioned below can guide you to adopt it to your situation.
There are four pieces of information that you will need in order to build the VLOOKUP syntax:
The value you want to look up, also called the lookup value.
The range where the lookup value is located. Remember that the lookup value should always be in the first column in the range for VLOOKUP to work correctly. For example, if your lookup value is in cell C2 then your range should start with C.
The column number in the range that contains the return value. For example, if you specify B2: D11 as the range, you should count B as the first column, C as the second, and so on.
Optionally, you can specify TRUE if you want an approximate match or FALSE if you want an exact match of the return value. If you don't specify anything, the default value will always be TRUE or approximate match.
Now put all of the above together as follows:
=VLOOKUP(lookup value, range containing the lookup value, the column number in the range containing the return value, optionally specify TRUE for approximate match or FALSE for an exact match).
In the sample data shown in the sheet1 and sheet2. Shee2 has ID column and Date column. Formula to be put in cell B2 of Sheet1 is:
=VLOOKUP($A2, Sheet2!$A$2:$B$6,2,0)
Fill down the formula and it will correctly pick dates from Sheet2 and fill in sheet1. Sample data screenshots are placed below.

VLOOKUP value not available to formula or function but it should be

I am using the following formula:
=VLOOKUP(E9, 'Raw data'!$A$1:$I$45857, 9, FALSE)
I have two tabs and I want one column in my first sheet to lookup the # value found in 'raw data' associated with the ID number found in column E (data begins on cell E9). my second tab, 'raw data', includes that same field as found starting on E9 in sheet 1 within the data range A1:I45857. The column I want returned from 'raw data' is the 9th column. I want to be exact matches only.
What I think excel is thinking - look for e9 in the array 'raw data' and when I see it, return the value that I find in the 9th column of that row within array 'raw data'.
What excel is saying - A value is not available to the formula or function
I am confused because the value is in fact available within that array. when I filter and search for just one of the IDs, I find it in both sheets. The data type is number for both columns and there are no rogue spaces or anything...
My goal is ultimately to take a subset of ids and look at the difference between the # found on sheet1 and the number found on 'raw data'. I am Vlookup-ing so that i can grab the # value on 'raw data, set it right next to the # i am comparing it to on sheet1 and then I can pivot the data to aggregate both of those numbers based on ID and create a calculated field showing the % difference between the two.
Any input on how to fix my vlookup or a workaround to join my # from 'raw data' to sheet1 based on a common ID is MUCH appreciated.
I recommend that you look into the combination of INDEX & MATCH, rather than VLOOKUP, for situations like this. VLOOKUP has 2 main flaws: (1) you have to order your data so that your search term is the left-most column of a continuous data block [as you have just seen]; and (2) it is volatile, meaning that when a column is inserted within your data block, it will no longer properly 'count' the number of columns to move to retrieve your data.
MATCH is like half of VLOOKUP. You give MATCH a specific column or row, and a value to search for, and it will simply return the number of cells in it had to move to find that value.
=MATCH(A1,B:B,0)
This says 'look at B:B, and tell me what row the value of A1 appears on'.
INDEX is like the other half of VLOOKUP. You give INDEX a group of cells (either a row, column, or a 2D range), and a specific row number (plus potentially a column number), and it will return the value for that cell.
=INDEX(C:C,5)
This gives you the value of cell C5, which is the 5th row found in the column given to INDEX. Combine these two formulas and it will return the value of column C, where column B matches A1:
=INDEX(C:C,MATCH(A1,B:B,0))
This formula gives an identical result to
=VLOOKUP(A1,B:C,0)
VLOOKUP looks simpler here, but INDEX & MATCH is much more versatile - in your case, you wouldn't have needed to reorder your data to get it to work, you could have used the formula:
=INDEX('Raw Data'!I:I,MATCH(E9,'Raw Data'!E:E,0))
Once you get into the habit of using INDEX / MATCH over vlookup, you will find that your data is a lot more flexible to manage.
Got it to work by making my ID field in 'raw data' the leftmost column.
You don't need to start the Vlookup in column A. If the ID column is not in column A, Vlookup can still work, as long as the ID column is to the left of the column you want to return. So, if you want to return the value from column I, and the ID column is in column F, you can leave the table as it is and change the Vlookup to
=VLOOKUP(E9, 'Raw data'!$F$1:$I$45857, 4, FALSE)
This will look for the match in column F and returns the value from the fourth column, which is column I.

How to create result table with vlookup from merged cells

I have this data table and i want another result table. when I write name of state ,result table can show all of company with data1,data2 and data3.I trying use vlookup but because there are merged cells the formula just show first row.
how can I fix problem?
If I'm understanding correctly, you want to set up a lookup range so that when you enter a particular state, you can see the data for all the companies that have data in that state. Here is one way to do that.
The first thing you would need to do is set up three columns to the left of the original table:
The first column holds the name of the state associated with each row of data
The second is an index that counts off the number of data rows in each state
The third combines the first two columns to produce a unique key value for each row in the table.
All the values in these three columns can be assigned by formula. The picture below shows the formulas for the first row of cells A9:C9, which are then copied down through row 27.
The next step is to lay out the new table, which is in cells Q8:U27 in my example.
There are several thing to note about the setup. First, the state that will be displayed is entered in cell Q9, which I've highlighted in yellow. To the left of the table, in column P, I've entered item numbers from 1 to 19, which will be needed to construct the key values for the lookups. The lookup formulas themselves are in cells R9:U27; in the picture, the formulas for the first row (R9:U9) are shown (they are then copied down through row 27).
It's worth taking a moment to look more closely at one of the lookups. Here is the formula for the first company name in cell `R9'.
=IFERROR(VLOOKUP($Q$9&$P9,$C$9:$N$27,4,0),"")
Looking at each of the arguments of the VLOOKUP in turn, $Q$9&$P9 concatenates the state name in cell Q9 with the item number (1 in this case), yielding the lookup value 'California1'. The lookup table is defined as the range $C$9:$N$27 - column C of that range is what the lookup value is matched against. The third argument is the column from which to return a value if the lookup is a match. The number 4 here corresponds with the company name column of the original table. Finally, the last argument is 0 (or equivalently, FALSE) indicating an exact match is required.
Finally, the VLOOKUP function is wrapped inside IFERROR. This catches the #N/A that would otherwise be returned when no match is found, replacing it with an empty string ("").

Resources