Search a column using entries from another column? - excel

Columns A:D are First Name, Last Name, Address, City. I have about 85 rows of information.
I'm trying to determine if a CITY (Column D) occurs in my list of cities (on another sheet, about 150 rows). It can provide me this answer in say, Column E.
I know VLOOKUP won't work because I need it to tell me ALL occurrences of the city name on multiple rows. I've tried to make INDEX-MATCH fit, but I can't figure out how to get it to do what I need (or if it can do what I need). I thought SEARCH would help, but the results don't seem to match reality (I can find entries).
Is there a formula that can do this for me? Basically, I need to know which of the entries match my separate list of cities

Just use COUNTIF()? (Adjust G2:G4 to the separate list of cities you have)
=IF(COUNTIF($G$2:$G$4,D2),"Is in the list","Is NOT in the list")

Vlookup will work, but it is not the most efficient way.
=if(iserror(vlookup(A1,'the other sheet'!B:B,1,false)),"not found", "found")
Index/Match will work, but you only need the Match part, anyway
=if(isnumber(match(A1,'the other sheet'!B:B,0)),"found","not found")
The Countif suggested by BruceWayne is the most efficient formula.

Related

Find a value in a range (any of multiple column or rows) and return the value in far left most column of that row

Looking for something like a typical index match formula that can look to the right and return value to the left, but look at all columns in a range. Take below valid formula for example.
(Excel 2021.)
Finds A1's value in column D, and it returns value from column C.
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$D$10,0))
In my ideal world I can Keep $D$1 and change $D$10 to $F$10 so it searches all columns D/E/F, and still returns C like below. However that does not work in our real world, any other ideas please? Thanks!
=INDEX($C$1:$C$10,MATCH(A1,$D$1:$F$10,0))
Update*
To clarify there are mix of letters and numbers. Also this table will be about 50k rows so hoping as simple as possible.
Also Column C will all be unique for sure, and D-F should be unique values but there is a chance a mistake and a few duplicates might be in.
You need MMUL() with INDEX(). Try below formula if you have Excel-365.
=FILTER(C1:C10,MMULT(--(D1:F10=A1),SEQUENCE(COLUMNS(D1:F1))))
For older version try
=INDEX($C$1:$C$10,LARGE(MMULT(--($D$1:$F$10=A1),TRANSPOSE({1,1,1}))*ROW($C$1:$C$10),1))
Since your INDEX/MATCH take from the same rows, you can first simplify your original search with
=XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10)
XLOOKUP combines HLOOKUP and VLOOKUP with exact match being the default.
This will work for searching three rows
IFERROR(IFERROR(XLOOKUP(A1,$D$1:$D$10,$C$1:$C$10), XLOOKUP(A1,$E$1:$E$10,$C$1:$C$10)), XLOOKUP(A1,$F$1:$F$10,$C$1:$C$10))
We can name the columns colC, colD, colE, and colF and it becomes
IFERROR(IFERROR(XLOOKUP(A1,colD,colC), XLOOKUP(A1,colE,colC)), XLOOKUP(A1,colF,colC))
As with other lookups, this returns the first value or #N/A error.
This could be made more scalable for higher number of rows if we are allowed to add a column somewhere.

VLOOKUP filling in blank spaces

So honestly I feel really dumb here. I have a very large file that has a lot of blank values where there should have populated a name, and I wanted to use a formula to fill those in. The data that I have is what appears in Columns A and B: A bunch of customer names and corresponding transaction codes (that repeat several times over), but blank spaces in a lot of places where the customer name should be. My attempt to fix this was to try filtering the data to get rid of the blank spaces, and use a VLOOKUP formula off that new table. Any ideas on what I'm doing wrong here? I don't care if it's a VLOOKUP, I just know there's an easier way to fix this that I'm not seeing, but none of the posts I've found fixed my issue...Thanks for any help you can give. Snapshot of Excel Table
Vlookup only performs matching left-to-right: the matching column has to be the first column of the range(D2:D13).
If you have Excel 365, you can use Xlookup:
=XLOOKUP(B7,E$2:E$13,D$2:D$13,,0)
or if not, you can use Index/Match:
=INDEX(D$2:D$13,MATCH(B8,E$2:E$13,0))
It might be more convenient to test for blank cells in column A and fill them in using a separate column if so, eg in C2:
=IF(A2="",XLOOKUP(B2,E$2:E$13,D$2:D$13,,0),A2)

Using VLOOKUP and not only match on first value

I'm trying to use VLOOKUP to match activities with product codes, but run into an issue since VLOOKUP always returns the first match. I did a mockup below to describe my issue. To the left, I have a table with activity names and product codes.
To the right, in column G, I want to, based on matching activity names in column F with activity names in column A, assign the activities product codes from column B.
When I use VLOOKUP, it only matches with the first activity name and give all the activities with the same name the same product codes. I need them to get different product codes even if they have the same name. I want my function to "take the next one" on the list, when the first one is taken.
Should I try to use another function to solve this? Is it impossible with VLOOKUP? My 'real' document has like 2000 rows, and the solutions I found on Youtube was not good to scale.
Thanks in advance. I'm new to here so if I should clarify my question in any way, feel free to tell me.
If the raw is around 2,000 rows, you can use a nested index match with helper columns.
Add a rank in column C with the formula =COUNTIF(A2:$A$2,A2)
Then apply the same ranking in your output part as well (Ensure Activity Name is sorted so that the formula works), Output rank formula =IF(J2=J1,I1+1,1)
Formula that lists out the Product Code {=INDEX($B$2:$B$3190,MATCH(I2,IF($A$2:$A$3190=J2,$C$2:$C$3190),0))}
This is an array formula, you get the curly brackets by hitting control+shift+Enter instead of just Enter upon keying in the formula
If you are using excel 365, you can use UNIQUE formula.
=UNIQUE(A2:B18)

How to sumif the vlookup value of a range?

I'm not sure how to explain what I am trying to achieve so I will start with the data I am working with:
1) A table that lists IDs corresponding to Games. Each game has several IDs.
2) A table that lists IDs and $ Earned on those IDs.
In another table, I have the list of games and want to return the sum of $ Earned on those games:
Tables 1,2,3
I was trying to do this with a combination of a SUMIF and VLOOKUP formula but I can't seem to find a way to do that because the VLOOKUP returns a value rather than a range. What I want to do is sum a sum_range ($ earned) if the lookup value of the range (game corresponding to the code) is a match.
I could simply add a column to the second table that returns the game of that code with a VLOOKUP. But the problem is that this would need to be done in a very large number of sheets, and with each time the new data is received.
Hopefully that made sense and thank you in advance for any help I can get!
Cheers,
Maria
Well this may be a bit of a cheat. if you look at your game code, you are either looking for basketball or baseball. So we could do a sum if the code contains one of those words.
If case sensitivity is important
=SUMPRODUCT(--(ISNUMBER(FIND("Basketball",B2:B16)))*C2:C16)
or if case sensitivity is not important
=SUMPRODUCT(--(ISNUMBER(SEARCH("Basketball",B2:B16)))*C2:C16)
B2:B16 would be your code in table 2
C2:C16 would be your $ earned column in C2
The formula would be placed where the ? cell is beside big win Basketball.
updated option for keyword
So if you are not looking for just baseball or basketball, but the entire string of the key words that you are looking for the total for, you could use the following provided the words in table three form part of the code when the spaces are removed.
=SUMPRODUCT(--(ISNUMBER(FIND(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
or
=SUMPRODUCT(--(ISNUMBER(SEARCH(SUBSTITUTE(B19," ",""),B2:B16)))*C2:C16)
This assumes the keyword your are looking for in the code is in B19. The substitute function removes the spaces to match your code.
In the second table add a (hidden) column, where you perform a VLOOKUP in the first table of the Code, retrieving the Game name.
Now you have something to base your SUMIF on: the value in the additional, hidden column should match the Game you have in your summary.

Can a countifs do this or do I need an array?

I have a data range B5:L100.
In column B is a string identifier, say 'X' or 'Y'.
In columns C:L we have different people's names entered (never more than once per row).
I want to count how many times a person's name appears in rows where column B is 'X'. The following formula doesn't work (using "Max" as the example person to search for).
Can you advise on what will do this elegantly?
=COUNTIFS(C5:L100,"Max",B5:B100,"X")
I think an array formula might be in order, but I'm not too experienced on those.
One way to do this is to just do it column by column:
=COUNTIFS(C5:C100,"Max",B5:B100,"X")+COUNTIFS(D5:D100,"Max",B5:B100,"X")... etc
Does the trick, but not too elegant if you have loads of columns to look through. I'm sure there's a tidier way using an array formula.
=SUMPRODUCT((C5:L100="Max")*(B5:B100="X"))

Resources