+ Reply to Thread
Results 1 to 11 of 11

Search & Match Functions return unexpected results

  1. #1
    Registered User
    Join Date
    03-05-2017
    Location
    Pflugerville, TX, USA
    MS-Off Ver
    2010 Home Edition
    Posts
    4

    Exclamation Search & Match Functions return unexpected results

    I am trying to create a search engine that will search the "A" column in all sheets in my workbook. Kind of like how a filter would do it for instance if I put in the search box "plane" it should find the word "airplane" etc...I can't use VBA, since this needs to work on my Android phone's Excel app. I also do not know of an Access app to work for this either.

    I think I could rig this up if I could get a function that would return the right results like I described above. VLOOKUP approximate match apparently doesn't do this correctly either from my Google search and testing. So I have tried functions MATCH and SEARCH functions. I am attaching an example spreadsheet that searches a short list, so you can see what I am talking about. It's like sometimes Search will return the right results and other times MATCH will, but neither is consistent.

    I appreciate any help you guys have to offer. I have a decent amount of programming experience, but still new to Excel Magic.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2016
    Posts
    5,911

    Re: Search & Match Functions return unexpected results

    Try this ...

    =MATCH("*"&B2&"*", $C$4:$C$6,0)

    Or:

    =VLOOKUP("*"&B2&"*",C4:C6,1,0)

  3. #3
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Search & Match Functions return unexpected results

    You want to count "words" or show words as result?
    Last edited by sandy666; 03-06-2017 at 01:53 AM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Search & Match Functions return unexpected results

    What variations of VLOOKUP() have you tried? You are correct that 4th argument=TRUE (approximate) match does not work for this, because your list is not set up for a binary search algorithm (I know that this is not well documented). I would have expected VLOOKUP() to work correctly with 4th argument=FALSE (exact match) and use wildcards in your lookup value. So VLOOKUP("*plane*",C4:C6,1,FALSE) should return the first instance of any cell containing "plane", so it should return "airplane". The same thing applies to the HLOOKUP() function or the MATCH() function if you enter 0 as the third argument.

    Where you are setting it up to read a cell for the search value, I don't know if you would want =VLOOKUP(b2,c4:c6,1,FALSE) and then enter '*plane* into b2, or put the wildcard into the vlookup function =VLOOKUP(CONCATENATE("*",b2,"*"),...). I might prefer the former, and leave the user the flexibility of using wildcards if they want, and what wildcards they want to use. I would probably preformat B2 as text so they don't need to use a leading apostrophe in front of an entry that starts with asterix (which Excel will want to interpret as the beginning of a multiplication formula).

    Whatever you decide, I would expect that you can get this to work if you use FALSE exact match in the 4th argument of the VLOOKUP() function and then use wildcards in the search text.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  5. #5
    Registered User
    Join Date
    03-05-2017
    Location
    Pflugerville, TX, USA
    MS-Off Ver
    2010 Home Edition
    Posts
    4

    Thumbs up Re: Search & Match Functions return unexpected results

    Thanks guys! This was what I was looking for. Don't know why I didn't think of trying wildcards, but that did work for the question in this post. I guess I assumed
    Exact Match in VLOOKUP meant that literally and Approximate Match meant just that. While I have everyone's attention on this thread. Is there a way to return a list
    of matches. An example would be great, but if could you at least point me in the right direction that awesome too.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Search & Match Functions return unexpected results

    I generally feel like the easiest way to return a list of matches is to use the built in filter tools (http://www.wikihow.com/Use-AutoFilter-in-MS-Excel ). The user would pull up the filter drop down, select "text filters" -> "contains" -> and enter the desired text string in the dialog.

  7. #7
    Registered User
    Join Date
    03-05-2017
    Location
    Pflugerville, TX, USA
    MS-Off Ver
    2010 Home Edition
    Posts
    4

    Re: Search & Match Functions return unexpected results

    Quote Originally Posted by MrShorty View Post
    I generally feel like the easiest way to return a list of matches is to use the built in filter tools (http://www.wikihow.com/Use-AutoFilter-in-MS-Excel ). The user would pull up the filter drop down, select "text filters" -> "contains" -> and enter the desired text string in the dialog.
    Yes, I already have it in a table where I can filter it. But the problem is that they are in separate sheets within the workbook and I don't want to have to go through each individual sheet to see if it is this one or that one every time I want to search for something. I wouldn't be opposed to if there was a way to some how concatenate all the sheets into one if it could be done automatically where I wouldn't have to copy and paste every time I made a change. As the columns are consistent in every sheet, but I still need the sheets separated so items are grouped together. If there is a better way of doing this I open to suggestions.

  8. #8
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Search & Match Functions return unexpected results

    I don't do this sort of "database management" stuff, so I am not very skilled at it. It sometimes seems to me that these kinds of question are easiest (long term) if you can compile everything into one, good database, then build queries and pivot tables and such off that database. I am not aware of utilities that help with compiling several small databases into a single database. I would recommend researching possibilities, because this might be the easiest and best way to do this task long term.

    I am optimistic that a formula solution for this is possible. Because lookups (especially linear, exact match lookups) can be processor intensive, this has the potential to be slow. Excel's lookup functions all return the first result, not multiple results. I have not thought through the details of the algorithm, but my first thought is to add a helper column to your tables that will look at B2, and compile a list of unique lookup values (plane1,plane2,plane3...) for each incidence of plane, then your lookup functions could search for those unique values.

  9. #9
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Search & Match Functions return unexpected results

    Quote Originally Posted by ilikerolls View Post
    Is there a way to return a list
    of matches.
    I don't know if this is a perfect fit for what you're looking for, but you can approximate a "Search" function via formula by using the following formula, array-entered with Ctrl + Shift + Enter instead of the regular Enter, then filled down:

    =IFERROR(INDEX($C$4:$C$11,SMALL(IF(ISNUMBER(SEARCH("*"&$B$2&"*",$C$4:$C$11)),ROW($C$4:$C$11)),ROW(1:1))-ROW($C$4)+1),"")

    Fill it down through as many cells as you think you'll need. It should auto-update as you change your search term in B2.

    If you want to search through ranges in multiple sheets, the easiest (formula) approach might be to use several versions of the formula above in columns alongside each other, but with each column tied to a different search range, so F4 and down returns matches from table 1, G4 and down returns matches from table 2, etc.

    Take a look at the attachment to see if it proves helpful.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-05-2017
    Location
    Pflugerville, TX, USA
    MS-Off Ver
    2010 Home Edition
    Posts
    4

    Thumbs up Re: Search & Match Functions return unexpected results

    Quote Originally Posted by CAntosh View Post
    I don't know if this is a perfect fit for what you're looking for, but you can approximate a "Search" function via formula by using the following formula, array-entered with Ctrl + Shift + Enter instead of the regular Enter, then filled down:

    =IFERROR(INDEX($C$4:$C$11,SMALL(IF(ISNUMBER(SEARCH("*"&$B$2&"*",$C$4:$C$11)),ROW($C$4:$C$11)),ROW(1:1))-ROW($C$4)+1),"")
    Wow this is the closest thing to what I was looking for thanks for sharing. I was able to apply this to my Excel sheet and return multiple matches as you described. Although I am doing something wrong here when applying this to my worksheet. For instance I type in the word "plane" and the correct results like "airplane" show up, but then something like "Air Conditioner" is in the list?? Or I type in "head" and "hammer" pops up, but not "headache"? Any clue as to why this happens? I tried adding the word "Air Conditioner" to your example and works as it should(doesn't show up when I type in "plane"). Do I need to format my search column in a certain way? My data is in Tables if that makes a difference? Right now it is set to "General". Should it be set to "Text"?

    If you want to search through ranges in multiple sheets, the easiest (formula) approach might be to use several versions of the formula above in columns alongside each other, but with each column tied to a different search range, so F4 and down returns matches from table 1, G4 and down returns matches from table 2, etc.
    Yeah this is kind of what I expected I would have to do in Excel, which I am OK with.

    It sometimes seems to me that these kinds of question are easiest (long term) if you can compile everything into one, good database, then build queries and pivot tables and such off that database.
    You make a good point Mr. Shorty. I do have some database experience fortunately with MySQL, Oracle, and DB2. I can't imagine MS Access being that difficult. I will take a look at this. I wouldn't mind using CAntosh's solution in the immediate short term though and I am curious what I am doing wrong with making this Search function not returning the expected results.

  11. #11
    Forum Expert
    Join Date
    05-20-2015
    Location
    Chicago, Illinois
    MS-Off Ver
    2016
    Posts
    2,103

    Re: Search & Match Functions return unexpected results

    When you get the mismatches on your sheet, do you notice that the "wrong" returns are always the same number of rows above/below a correct match? Without seeing your sheet, I would guess that the "-ROW($C$4)+1" part of the formula is the issue. You want this portion of the formula to always equal one less that the row that the your data list starts in. In the sample I attached, the data is in C4:C11, so we needed that portion to subtract 3, so -ROW(C4) =-4, plus one gets us to -3. My guess would be that the data range on the problematic sheet doesn't start on row 4, so the formula needs to be adjusted. I hope that makes sense?

+ 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. Replies: 1
    Last Post: 01-24-2017, 11:33 PM
  2. [SOLVED] Code to search Excel and return results even if part of search text is present
    By Taoyuan00 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-30-2016, 09:20 AM
  3. [SOLVED] Display search results inluding results that match patrially
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2013, 08:52 AM
  4. [SOLVED] Using Index Match or Vlookup giving unexpected results on imported data
    By jacob@thepenpoint in forum Excel General
    Replies: 2
    Last Post: 07-03-2012, 05:49 PM
  5. How to search and return results
    By the deeb in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 02-09-2011, 05:57 PM
  6. Return search results??
    By itsacatfish in forum Excel General
    Replies: 3
    Last Post: 09-02-2010, 01:33 PM
  7. search tabs and return results
    By korr77 in forum Excel General
    Replies: 14
    Last Post: 02-04-2010, 05:20 AM

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