Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Spreadsheet: Get cell data if 2 conditions are met. Help?
I have a sheet in a workbook that gets its information from another sheet (within the same workbook).
The sheet with the data has hundreds of rows but only 4 columns.
Example of what I need:
Sheet 1, Cell __ : Needs to look in Sheet2, and find a row where "name 1" appears in Col A, AND, "name 2" appears in Col C, of the SAME row, and then to return the number in Col B of that row.
There is only ONE instance where "name 1" is in Col A with "name 2" in Col C.
If the names are found reversed ("name 1" in Col C, "name 2" in Col A), then I don't want to pass the data.
So, how can I write this function?
2 Answers
- AngeaLv 49 years ago
Hi, I've found a method to create the results you want. It is not fanciful but it works.
You can see my spreadsheet here: http://apps.memopal.com/d/?SUUUV2T5
There are a few assumptions I made.
1) The names are spelled in the same manner
e.g. Cathy in Sheet1 Name1 is spelled as Cathy in Sheet2 Name1, and not cathy or CATHY etc
2) All [Name1 n Name2] columns are sorted in ascending order (more info below)
3) The sorting of [Name1 n Name2] columns must be done before the Lookup formula is written into Sheet1.
Since each Name1+Name2 would be a unique index, I created a new column in Sheet1 and Sheet2 where I use Concatenate function to put them together. I label this column [Name1 n Name2].
After that's done, I sorted the table of each worksheet according to [Name1 n Name2] in ascending order. This is important otherwise the lookup formula to find the number in Sheet2 Col B will not work properly.
In Sheet1, I created another column to get the number in Sheet2 Col B. The formula I use is :
=LOOKUP(C2,Sheet2!D2:D8,Sheet2!B2:B8)
This formula will do the following
i) See what's in the [Name1 n Name2] cell I indicated in Sheet1
ii) Go to the indicated range of rows in [Name1 n Name2] of Sheet2 and find a match.
iii) Once a match is found, get the data from the same row in Column B
iv) Return the data to Sheet1
Minor problem: Once you copy/drag the lookup formula to the cells below it, it will become
=LOOKUP(C3,Sheet2!D3:D9,Sheet2!B3:B9)
=LOOKUP(C4,Sheet2!D4:D10,Sheet2!B4:B10)
=LOOKUP(C5,Sheet2!D5:D11,Sheet2!B5:B11)
etc
As you can see, the range of rows to look thru moves down by one row each time. Excel does this automatically. This is why the [Name1 n Name2] columns must be sorted in ascending order before the lookup formula is written into Sheet1. That way as the range of rows to search moves downward, you won't miss a thing.
Alternative: Change =LOOKUP(C2,Sheet2!D2:D8,Sheet2!B2:B8) to
=LOOKUP(C2,Sheet2!$D$2:$D$8,Sheet2!$B$2:$B$8). After that when you copy and paste the formula downward, the cell reference of Sheet2 will remain the same.
Another alternative: write this formula
=LOOKUP(C2,Sheet2!Dx:Dy,Sheet2!Bx:By)
Copy and Paste the formula into each cell of the Sheet 1 column where u want the Sheet 2 Col B data to be.
Select that column then use 'Find and Replace' to replace x with the first Row number that has data in Sheet2 and replace y with the last Row number that has data in Sheet2.
The disadvantage of this is, you would need to remember this alternative and repeat it if u add more rows to Sheet 1 in the future.
I hope this will help you.