Need simple look up or match formula

Thankful01

New Member
Joined
Nov 20, 2009
Messages
3
I want to return all the results from a match or lookup formula instead of the first result.

Here is what I have

A B
NAME BIRTHDAY
Sally 1-May
Sam 5-Jun
Suzy 1-Jan
Tom 5-Jun
Zach 5- Jun


Today's Date: cell F3 (pretend today's date is 5-Jun)

Today's Birthdays: cell F4 (here I want a list of everyone with a birthday today. In this case, cell F4 should say: Sam, Tom, Zach )

What formula would you use to get all the matches? If there are no matches, I want the cell to say "none"

I'm not a master at excel but found this forum so I thought I would ask. Can anyone help me with a formula to do this? You will need to write it out for me as I am new to Excel instead of saying just use "this function".

Thanks.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Thanks! Did I mention I was a beginner? That link went whoosh over my head. I do not speak excel yet.


Here's what I've got:

data range A3:B7

Find Match to cell F3 in column B3:B7

return the corresponding values in column A3:A7 of all matches found into cell F4 seperated by ","

if no matches, return "None" into cell F4


I was so excited to figure out how to get one match using this:

=INDEX(A3:A7,MATCH(F3,B3:B7,0))


But I'm stumped on how to get all the matches seperated by a "," into the cell and return "none" if there are no matches. Surely there is a way to do this?


Can anyone of you Excel masters hold my hand on this? I don't speak excel yet, I'm still trying to figure it out on my own. My real database contains about 130 kids and their birthdays but the layout is pretty much the same ... I don't know if that matters...but from what I've found, it looks like match can look through that many records.

Thanks!
 
Last edited:
Upvote 0
The thread starts by saying that it isn't possible using standard "native" Excel functions. You need to use some VBA code (Visual Basic for Applications) to add a User-Defined Function to your workbook.

It's not that hard to do.

Before I explain it, if you just want a list of names with a certain birthday, you could explore another option using Pivot Tables. This would give you a drop-down list of all the birthdays and, when you selected one, it would give you a list (i.e. a column of cells) of the relevant names.

Anyway, to create the UDF:

Press Alt+F11 to open the VBA Editor.
Go View > Project Explorer
Find your workbook in the list of projects.
Right-click your workbook's name and choose Insert > Module
This should open up a blank "code window".
Into this window paste the following:

Code:
Function ConcatIf(ByVal compareRange As Range, ByVal xCriteria As Variant, Optional ByVal stringsRange As Range, _
                            Optional Delimiter As String, Optional NoDuplicates As Boolean) As String
Dim i As Long, j As Long
With compareRange.Parent
Set compareRange = Application.Intersect(compareRange, Range(.UsedRange, .Range("a1")))
 End With
If compareRange Is Nothing Then Exit Function
If stringsRange Is Nothing Then Set stringsRange = compareRange
Set stringsRange = compareRange.Offset(stringsRange.Row - compareRange.Row, _
                                            stringsRange.Column - compareRange.Column)
For i = 1 To compareRange.Rows.Count
    For j = 1 To compareRange.Columns.Count
        If (Application.CountIf(compareRange.Cells(i, j), xCriteria) = 1) Then
            If InStr(ConcatIf, Delimiter & CStr(stringsRange.Cells(i, j))) <> 0 Imp Not (NoDuplicates) Then
                ConcatIf = ConcatIf & Delimiter & CStr(stringsRange.Cells(i, j))
            End If
        End If
    Next j
Next i
ConcatIf = Mid(ConcatIf, Len(Delimiter) + 1)
End Function

(You don't really need to know what all that means.)
Now press Alt+Q to return to Excel.
In cell F4 enter the following formula:

=concatif(B3:B7,F3,A3:A7,", ",FALSE)
Hope that helps.
 
Upvote 0
Crying TEARS of Joy!!

It worked on my real database too!!! WAHOOOOOOOOOOOOOOOOOO!!!! You don't know how many hours I spent trying to find a solution on the internet and how many friends I bugged!!

THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

*Bows to the Excel Master* :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top