+ Reply to Thread
Results 1 to 8 of 8

Macro not finding partial matches

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Macro not finding partial matches

    User enters either a First Name in D4, Family Name in D6 or Project in Col D9 of the Input Form

    For this example Database has variations on two Project names in Col C, but the "real" file can also have variations in First or Family Names.

    Need Macro to search each Database row. If it finds a record with a partial or whole match to whatever is in Col D, it should copy the Data to the next free row from L4 downwards.

    Unfortunately it isn't doing it, but I can't see why.

    Please Login or Register  to view this content.
    Any suggestions, pointers, solutions or alternatives welcomed as ever.

    Ochimus
    Attached Files Attached Files
    Last edited by Ochimus; 04-21-2018 at 01:37 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro not finding partial matches

    Hi Ochimus,

    Instead of trying to do this problem using VBA, why now learn a bit more about the Advanced Filter that is built into Excel and *Wildcard* searches?

    https://www.ablebits.com/office-addi...vanced-filter/
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,265

    Re: Macro not finding partial matches

    You could use a formula:

    in M4

    =IFERROR(INDEX(DATABASE!$A$2:$D$10,SMALL(IF((ISNUMBER(SEARCH('INPUT FORM'!$D$4,DATABASE!$A$2:$A$10)))*(ISNUMBER(SEARCH('INPUT FORM'!$D$6,DATABASE!$B$2:$B$10)))*(ISNUMBER(SEARCH('INPUT FORM'!$D$9,DATABASE!$C$2:$C$10))),ROW($A$2:$A$10)-ROW($A$2)+1,""),ROWS($1:1)),COLUMNS($A:A)),"")



    Copy across

    in L4

    =IFERROR(INDEX(DATABASE!$A$2:$D$10,SMALL(IF((ISNUMBER(SEARCH('INPUT FORM'!$D$4,DATABASE!$A$2:$A$10)))*(ISNUMBER(SEARCH('INPUT FORM'!$D$6,DATABASE!$B$2:$B$10)))*(ISNUMBER(SEARCH('INPUT FORM'!$d$9,DATABASE!$C$2:$C$10))),ROW($A$2:$A$10)-ROW($A$2)+1,""),ROWS($1:1)),4),"")

    Array formula so enter with C+S+E

    EDIT: needs modifying if all 3 are not selected!!!
    Attached Files Attached Files
    Last edited by JohnTopley; 04-21-2018 at 02:17 PM.

  4. #4
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,265

    Re: Macro not finding partial matches

    Updated:

    =IFERROR(INDEX(DATABASE!$A$2:$D$10,SMALL(IF((IF($D$4="",1,ISNUMBER(SEARCH('INPUT FORM'!$D$4,DATABASE!$A$2:$A$10))))*(IF($D$6="",1,ISNUMBER(SEARCH('INPUT FORM'!$D$6,DATABASE!$B$2:$B$10))))*(IF($D$9="",1,ISNUMBER(SEARCH('INPUT FORM'!$D$9,DATABASE!$C$2:$C$10)))),ROW($A$2:$A$10)-ROW($A$2)+1,""),ROWS($1:1)),COLUMNS($A:B)),"")
    Attached Files Attached Files

  5. #5
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,265

    Re: Macro not finding partial matches

    Re your VBA: it does not check for combinations of criteria: if it matches on any one criterion it outputs a record without checking whether other criteria are met.

    So if D4=John D6= Smith, it will return all John(s) but NOT Just John Smith

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Macro not finding partial matches

    First, thanks to both for immediate responses.

    Appreciate the Array formula approach and I am used to it, but I want VBA because certain "end users" have a happy habit of overwriting formulae. As the VBA approach just pulls over numbers into each cell, whatever they do can't affect the form next time round.

    I also take John's latest point, as the Code as written will stop at the first match, and lists all the matching records. Have to chat to the End User and see if they want "multi- cell" criteria!

    So hopefully someone can see the "hole" in the Code and show me what it should say?

    Ochimus

  7. #7
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,265

    Re: Macro not finding partial matches

    InStr parameters are reversed:

    If InStr(1, .Range("D4").Value, Sheet2.Range("A" & x).Value, vbTextCompare) > 0

    should be

    If InStr(1, Sheet2.Range("A" & x).Value, .Range("D4").Value, vbTextCompare) > 0

    You also need to check if "input" parameters are blank as blank parameters are selected.

    I would suggest you uss the following rather than Sheet1/Sheet2

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 04-22-2018 at 12:28 PM.

  8. #8
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Macro not finding partial matches

    Ended up with this Code that checks whether any of three input boxes contain data, then finds and copies across all the records on the Database that completely or partially match whichever cell was filled in.

    Posting it here as it may help someone else.

    Please Login or Register  to view this content.
    May also lead someone to post a more elegant solution that does the job?

    Ochimus

+ 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. [SOLVED] Comparing two data sets and finding matches or non matches
    By b0bertini in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-18-2017, 09:34 AM
  2. Find Partial matches
    By KTM450 in forum Excel General
    Replies: 11
    Last Post: 11-05-2015, 10:09 PM
  3. [SOLVED] Multiple partial matches
    By Grinfactor in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-28-2014, 01:15 PM
  4. [SOLVED] Finding partial text matches compared to a range
    By grifta67 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-17-2014, 04:38 PM
  5. Finding dupllicates using partial matches
    By cmax979 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-09-2013, 09:52 PM
  6. Finding Partial String Matches
    By evs in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-02-2009, 06:22 AM
  7. [SOLVED] Autofiltering for partial matches
    By PeterJordan in forum Excel General
    Replies: 1
    Last Post: 01-12-2006, 05:35 PM

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