+ Reply to Thread
Results 1 to 5 of 5

Match Failing When It Shouldn't

  1. #1
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Match Failing When It Shouldn't

    Working out some bugs in my VBA project.

    Please Login or Register  to view this content.
    This code will isolate a date from a string (eg from "SRF_WP_07Jan19-13Jan19.xlsm" 07-Jan-19. rnglo = 1/7/2019
    It takes the value of rnglo and seeks a match in worksheet("sheet2").range("K2:K21") to return it's row number. This range holds true dates displayed as "d-mmm". (the values are a result of a formula if that matters).

    I am getting an error with the line in red advising me that it was unable to find a match despite 7-Jan being found at K7.

    Am I missing something?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,307

    Re: Match Failing When It Shouldn't

    Attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: Match Failing When It Shouldn't

    The code without the sheet could make debugging this difficult. I note that your MATCH() function is an "exact" match -- meaning that the date in rnglo must match the corresponding entry in the spreadsheet exactly (and Excel -- like many things computers do -- can get annoyingly technical about what exactly means).

    In my quick mockup, the lookup failed and I think it has to do with data types. A spreadsheet only knows two data types -- double floating point or text/string. VBA, of course, can recognize many more data types. Not knowing anything about the internal workings of Excel's MATCH() function (designed to work mostly with spreadsheet data -- so doubles or string), my guess is that something about the type conversion (or lack of type conversion) causes the data type between the value in rnglo passed to the match function and the double precision or text values in K2:K21 is causing the MATCH() function to fail to find the match.

    Knowing that the spreadsheet only recognizes double or string, I tried assigning rnglo a double:
    Please Login or Register  to view this content.
    -- knowing that the dates in my test sheet were true date/time serial numbers -- so they are stored as doubles. That seemed to allow the match function to locate the correct entry. My suggestion would be to avoid some of the ways that data types might mismatch by making sure that your values in the spreadsheet (whether double or text) and VBA are of the same data type.

    If you want us to get serious about debugging your spreadsheet, then do as TMS suggests and upload an actual workbook (dummy data, as necessary) for us to look at.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Match Failing When It Shouldn't

    1/7/2019 may exist on your spreadsheet. but if you format the cell as general does it still look like 1/7/2019 or does it look like 43647

    If 1/7/2019 then check if your data has spaces before or after

    if 43647 then use date value to convert you search string into a number.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  5. #5
    Forum Contributor
    Join Date
    06-15-2009
    Location
    Ontario, canada
    MS-Off Ver
    Office 365
    Posts
    371

    Re: Match Failing When It Shouldn't

    Thank you all for your support!
    With MrShorty's suggestion, I added the CDbl to the code and things appear to be working properly now. I guess there was something not right about 1/7/2019 that my rnglo formula calculated.
    I'm happy that this was an easy fix. It would have taken me a long time to desensitize my workbook and such changes I suspect might have compounded problems.

+ 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. Calculated Field - Formula Failing to Match Text
    By curlydog in forum Excel Charting & Pivots
    Replies: 9
    Last Post: 01-16-2018, 09:24 AM
  2. SumIf Index Match - 4 conditions (failing miserably! :(
    By Keelin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-10-2014, 07:26 AM
  3. INDEX MATCH MATCH working great and then failing on me.
    By HeikEve in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-25-2013, 01:40 PM
  4. Shouldn't IF then work?
    By ccampbell14 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-12-2013, 04:10 PM
  5. Shouldn't DDB and VDB(...,True) be the same
    By lucabol in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-27-2008, 06:53 AM
  6. # signs where there shouldn't be....
    By dramajuana in forum Excel General
    Replies: 6
    Last Post: 08-14-2006, 05:25 PM
  7. Hyperlinking when it shouldn't...
    By B.C.Lioness in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-17-2005, 03:06 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