+ Reply to Thread
Results 1 to 7 of 7

Database Search VBA Function

  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Database Search VBA Function

    I have an excel workbook that stores numerous worksheets containing lists of people's names. I want to add a worksheet with Last names inputted in column A, First names inputted in column B, and a function in column C that Takes the name in column A and searches all of the Last names in the rest of the workbook (accross multiple worksheets) for a match. If no match is found the cell in column C remains empty. If a match is found then the function takes the name in column B and searches all of the first names is the rest of the worksheet (accross multiple worksheets) for a match. If a match is found then the cell in column C returns: "Name Found"; otherwise it remains empty. This is the function that I have been working on, but I am new at this, and I can't quit figure it out. The function appears to run, but it returns: "#VALUE" in the cell in column C. I need help figuring out what the problem(s) is(are). This is the function as I have it:


    Function CheckNames(LastName, FirstName, SearchRange1, SearchRange2)



    If LastName = SearchRange1 Then
    If FirstName = SearchRange1 Then
    CheckNames = "Name Found"

    Else
    If LastName = SearchRange2 Then
    If FirstName = SearchRange2 Then
    CheckNames = "Name Found"
    Else: CheckNames = " "


    End If
    End If
    End If
    End If




    End Function

  2. #2
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Database Search VBA Function

    I have attached "Example" workbook to show what I want the function to look like.
    Attached Files Attached Files

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Database Search VBA Function

    tmkid,

    Welcome to the forum!
    The below code has the following assumptions:
    -The sheet where you're entering the CheckNames formula is the first sheet
    -All other sheets have the Last Names in column A
    -All other sheets have the First Names in column B
    -Looking for partial matches

    With those in mind, give this code a try:
    Please Login or Register  to view this content.


    Then you could use the formula like this, where A2 contains the Last Name and B2 contains the first name:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  4. #4
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Database Search VBA Function

    THANKS! That works perfectly in my example. The Last Name column in my database is column C, and the First Name column in my database is Column D. How do I change the code so that is references columns C and D instead of columns A and B?

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Database Search VBA Function

    Change all instances of "A" to "C". The .Offset(, 1) looks in the cell to the right, so it will automatically look in column D for the first name if you switch all of the "A"'s to "C"'s.

  6. #6
    Registered User
    Join Date
    07-29-2013
    Location
    United States
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Database Search VBA Function

    It did! Thank you so much!!

  7. #7
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Database Search VBA Function

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    How to mark a thread Solved
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word "Title" you will see a dropdown with the words "No prefix"
    Change to "Solved"
    Click Save

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Search function in a database
    By silversurfa23 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-26-2013, 06:25 PM
  2. Search function in database
    By Dr.malle in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-2013, 03:23 AM
  3. Create 'search engine' function Excel database.
    By tbrown3 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-22-2013, 09:52 PM
  4. Two Criteria Database Search Function
    By super21 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-06-2012, 11:25 PM
  5. Search function in massive database
    By Marvlin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-03-2008, 05:57 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1