Excel if Function,select cell in line with match - excel

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.

Related

Excel - Find matching values and copy different cell

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).

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.

Reference named ranges in external workbook with formula criteria

Need Help on Named Ranges in Formulas:
I have a second workbook ('TEST.xlsx') as the destination, referencing worksheet-scoped named ranges (in 12 columns X 75 rows) in the source workbook ('FLOW.xlsx'). I want to create a formula that will match a look-up value (a date entered into cell C3 in TEST that will return the matching named range IF there are 2 or more blank cells in that matched named range/column and the remaining named ranges/columns in that set of 12 columns with 2+ blank cells. The 12 separate columns in the source workbook ('FLOW') are named by month, year and location (ex., "jan_2019_class.1","feb_2019_class.1", etc.), the worksheet columns being C, H, M, R, W, AB, AG, AL, AQ, AV, BA, and BF. The rows are 80-155. I've only been able to make a simple working COUNTBLANK formula in my TEST workbook, ex.:
=COUNTBLANK('[FLOW.xlsx]Class_1-Chart'!jan_2019_class.1)
But NOT for successive columns (with different named ranges and the columns are non-sequential); and I can't figure out the functioning formula to combine with this to get the count AND data returned by criteria as described above. Please, no VBA/macros.
Thank you in advance for the help!
'TEST.xlsx' Screen Shot-RVSD
FLOW.xlsx- sample screenshot
There are many approaches but I personally prefer the use of helper rows/columns/cells and named ranges.
In my demonstration I used two class attendant schedule in two different year from January to June as shown below (they are sitting in Column C to M in my example):
As shown above, I have added two helper rows on top of each schedule. The first helper row is used to find out if there is 2 or more vacancies in each month, if so returns TRUE. I have given the name check.2019.class.1 and check.2021.class.5 for each of them.
The second helper row is simply showing the range name of each month such as jan_2019_class.1, feb_2019_class.2 etc. I have given the name NameRng.2019.class.1 and NameRng.2021.class.5 for each of them.
On the TEST sheet I have the following set up:
where the look up value in cell C3 is actually returned by a formula so it can be "dynamically" changed by the user. Please note in the following formula I used a name ClassNo which is essentially the value from cell B3.
=B2&"_"&B1&"_class."&ClassNo
I have also named cell C3 as Start_MthYrClass which will be used in my following formula.
The formula for looking up the first available month in 2019 if the start month is jan_2019_class.1 is:
=INDEX(NameRng.2019.class.1,MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0))*Check.2019.class.1,0))
Please note it is an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar otherwise they will not function correctly.
The logic is to first "filter" the range NameRng.2019.class.1 using this formula =TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,NameRng.2019.class.1,0), in which ROW($1:$11) represents {1;2;3;4;5;6;7;8;9;10;11} and TRANSPOSE will turn it into {1,2,3,4,5,6,7,8,9,10,11}. This range of numbers represents the column index in that specific range which is Column C to M (in your case it would be ROW($1:$56) as your data is in Column C to BF). Then I use MATCH to return the start column index of the look up month jan_2019_class.1, and it should return 1 as this month starts in the 1st place/column in the range NameRng.2019.class.1. So this is what I am actually comparing: {1,2,3,4,5,6,7,8,9,10,11}>=1, and it will return {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE}.
Then I multiply the above result with range Check.2019.class.1 which is essentially {FALSE,0,FALSE,0,TRUE,0,FALSE,0,TRUE,0,TRUE}. Then I will get {0,0,0,0,1,0,0,0,1,0,1}. FYI in Excel TRUE=1 and FALSE=0, so TRUE x FALSE = 0 while TRUE x TRUE = 1.
Lastly, I use MATCH to find out the position of the first 1 in the above result which is the 5th place/column, and then use INDEX to return the corresponding value from range NameRng.2019.class.1 which is mar_2019_class.1.
Here is a more universal formula which allows you enter it in the first cell C6 and drag it down to apply across board, if you have given names to the relevant cells and ranges in the same way as what I have demonstrated.
=IFERROR(INDEX(INDIRECT("NameRng."&B6&".class."&ClassNo),MATCH(1,(TRANSPOSE(ROW($1:$11))>=MATCH(Start_MthYrClass,INDIRECT("NameRng."&B6&".class."&ClassNo),0))*INDIRECT("Check."&B6&".class."&ClassNo),0)),"")
It is also an array formula so you MUST press Ctrl+Shift+Enter upon finishing the formula in the formula bar.
It is essentially the same formula as the first one but I have added IFERROR to return a blank cell if there is no match, and I used INDIRECT to refer to the named ranges dynamically based on the year and class number chosen.
Now, if I change the look up criteria to mar_2021_class.5, here is an updated result:
Let me know if you have any questions. Cheers :)

IF Function/VLOOKUP Combo

So this seems like it should be pretty easy. I could just concatenate and make another column in the data to make a unique combo and get my answer. But that just seems so messy. So here I am reaching out to you fine folks to pick your brains.
I want to look up HQLine and Description in the MPCC tab to return the correct MPCC Code. I tried a couple IF statements with VLOOKUPS but couldn't get it right.
So I need to look up BK3 Positive Crankcase Ventilation (PCV) Connector in the MPCC tab. So it needs to match BK3 and the Long description and then give me the correct code.
Here is the missing data file
Here is the MPCC export list that I want to search
Use SUMIFS.
SUMIFS will find the sum in a table of rows that meet certain criteria. If the MPCC is always a number, and the MQAb-LongDescription is always unique, SUMIFS will find the correct ID.
=SUMIFS(Sheet1!C$2:C$100,Sheet1!A$2:A$100,A2,Sheet1!B$2:B$100,B2)
where Sheet1!A$2:A$100 is the HQAb data, Sheet1!B$2:B$100 is the Long Description data, Sheet1!C$2:C$100 is the MPCC Number data, A2 is the HQLine, and B2 is the Description.
The formula would go in C1.
More information on VLookup with Multiple Criteria
You can use an Index/Match with multiple criteria.
I'm assuming that you will put this formula in "Sheet1", cell C2, and your lookup data is in a sheet called "Sheet2", columns A, B, C from row 2 to 30.
Put this in Sheet1, C2:
=INDEX(Sheet2!$C$2:$C$30,MATCH(A2&B2,Sheet2!$A$2:$A$30&Sheet2!$B$2:$B$30,0))
(Enter with CTRL+SHIFT+ENTER) and drag down.)
Adjust the ranges as necessary.
lets assume your first Table is on sheet 1 in the range A1:C11 and the MPCC codes are located on Sheet 2 in the range A1:C32. Each table has a header row so your data really starts in row 2.
Similar to BruceWayne's answer of using an array formula, you can bring the array calculation inside of a formula and avoid the special array treatment. There are a few functions that can do this. I will demonstrate with the SUMPRODUCT function;
On Sheet 1, Cell C2, use the following formula:
=INDEX('Sheet 2'!$C$1:C$32,SUMPRODUCT((A2='Sheet 2'!$A$2:A$32)*(B2='Sheet 2'!$B$2:B$32)*row('Sheet 2'!$A$2:A$32))
Explanation:
When the value in A2 matches the value in the range in the second sheet it will be true and false when it does not. when True False get used in math operations they are treated at 1 and 0 respectively. Therefore the only result from your two search criteria will be the rows where A2 match is true and B2 match is true and this will have a value of 1. The 1 will then be multiplied by the row number. Since all other results will be 0 since your list is a unique combination, the sum part of sumproduct will sum up to the row number where your unique row is located. This in turn is used by the indext function to return the row to give your unique number.

Formula to deliver answer that is in another sheet, to the left of a matched cell

I am working on a formula that delivers text from a cell in another sheet, that is to the left of a matched cell. This is as far as I have got.
=LOOKUP(A2,Sheet1!$A$1:$A$46729,Sheet1!$B$2:$B$46729)
In sheet 1 there is a selection of product data. There are product numbers in column A and there needs to be the correct barcode placed in each cell in column B. In sheet 2 there are also product codes in column A and barcodes in column B. However there are significantly more rows of data in Sheet 2.
What is needed is a formula to place in Sheet1!B2 that looks up Sheet1!A2 in Sheet2!A2:A50000. If A2 is matched at e.g. Sheet2!A90, then the result in Sheet1!B2 should be the value in Sheet2!B90. The specific issue I am having is getting the Sheet2!B90 in Sheet1!B2.
You can use Index/Match:
=Index(Sheet2!$B$2:$B$46729,Match(A2,Sheet2!$A$2:$A$46729,0))
Or VLOOKUP:
=VLOOKUP(A2,Sheet2!$A$2:$B$46729,2,false)
The last parameters of the MATCH and VLOOKUP functions respectively are very important as it forces it to search for an exact value and not assume a sorted list. VLOOKUP would no longer work if you reversed columns A and B on Sheet2 because the lookup column has to be the first column in the lookup range.

Resources