+ Reply to Thread
Results 1 to 21 of 21

Error 0438 while using MATCH

  1. #1
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Error 0438 while using MATCH

    Hi,

    I'm writing a little macro for our school HR department to calculate FMLA days.

    Please Login or Register  to view this content.
    I'm trying to get the user to just type in the date (MM/DD/YY) instead of their typing in the cell the date is found in the spreadsheet, like B28. So I was hoping to use "Application.Match(Application.DateValue(beginLeave), Range("B1:B366"), 0)" to return the row where the date is found and concatenate with the appropriate column letter, so I can reuse my existing code. However, it's throwing error 438 ("object doesn't support this property or method.") Could anyone please try to tell me why? thank you!!
    Attached Images Attached Images
    Last edited by tadhg_mac_nuadat; 08-25-2022 at 09:57 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    05-03-2022
    Location
    Halifax,Canada
    MS-Off Ver
    365
    Posts
    326

    Re: Error 0438 while using MATCH

    Application.Match is not valid . it's Application.WorksheetFunction.Match

    ATTENTION : I've been corrected in that my post is incorrect ... please ignore ..

    Peer review is so important ... makes us all smarter
    Last edited by nimrod1313; 08-25-2022 at 11:19 AM. Reason: information not correct

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: Error 0438 while using MATCH


    Wrong ! As Application.Match is valid, WorkSheetFunction was added just in order to crash VBA if an error is met ...

  4. #4
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Quote Originally Posted by nimrod1313 View Post
    Application.Match is not valid . it's Application.WorksheetFunction.Match


    Also not you fix this you may get a message of "Unable to get the Match property " ... this will occur if match is not found
    ... you may want some error trapping for that scenario like this ..

    Please Login or Register  to view this content.
    if this has helped please consider clicking "add reputation" ..
    Thanks, but adding WorksheetFunction didn't change anything as Marc said. Still getting same error. Could it have something to do with the user inputting the date as a string and its not being interpreted correctly?

  5. #5
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Error 0438 while using MATCH

    Try:
    Please Login or Register  to view this content.
    Or:
    Please Login or Register  to view this content.
    If things don't change they stay the same

  6. #6
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Quote Originally Posted by CheeseSandwich View Post
    Try:
    Please Login or Register  to view this content.
    Or:
    Please Login or Register  to view this content.
    Many thanks but that just threw error 13 (type mismatch) and Error 2042 when I printed the output to the console.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Error 0438 while using MATCH


    As the date should be entered according to the Windows Regional settings in order to be recognized as a valid date
    so easy to check with VBA function IsDate then can be converted via CDate as a true Excel date ...

  8. #8
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2503
    Posts
    1,485

    Re: Error 0438 while using MATCH

    The way i see it the string value was not being converted to a numeric value - meaning Excel does not see it as a date.

    When i print 'DateValue(CDate(beginLeave))' i get a numeric value which means that Excel can understand it as a date.

    Are the date values you hold in column B dates or are they just text, you can test by adding a formula in column C like =B2+1, see if you get an error or if the date increments by one day.

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Lightbulb Re: Error 0438 while using MATCH


    Another way as the date entry is in an Excel inner original format whatever the Regional Settings could be
    is to directly allocate the text date to a cell via the Formula property then Excel converts it automatically to a real date ...

  10. #10
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Quote Originally Posted by CheeseSandwich View Post
    The way i see it the string value was not being converted to a numeric value - meaning Excel does not see it as a date.

    When i print 'DateValue(CDate(beginLeave))' i get a numeric value which means that Excel can understand it as a date.

    Are the date values you hold in column B dates or are they just text, you can test by adding a formula in column C like =B2+1, see if you get an error or if the date increments by one day.
    Thank you, everything in Column B is formatted as dates. I tried printing "DateValue(CDate(beginLeave))" and that gave me an overflow error.

  11. #11
    Valued Forum Contributor
    Join Date
    05-03-2022
    Location
    Halifax,Canada
    MS-Off Ver
    365
    Posts
    326

    Re: Error 0438 while using MATCH

    Wrong ! As Application.Match is valid, WorkSheetFunction was added just in order to crash VBA if an error is met
    I stand corrected ... thanks for the diplomatic put education

  12. #12
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Quote Originally Posted by Marc L View Post

    As the date should be entered according to the Windows Regional settings in order to be recognized as a valid date
    so easy to check with VBA function IsDate then can be converted via CDate as a true Excel date ...
    Thank you, not sure entirely what you mean as I'm not an IT guy . . . just trying to help out HR as they are even more clueless than me. I am using Excel for Mac though; not sure if this makes a difference? They will be running the macro on Windows PCs though....

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Error 0438 while using MATCH


    As a reminder Application.Match works in conjunction only with a Variant variable so easy to check via IsError & IsNumeric VBA functions
    without the need of an useless On Error Resume Next ...

    You should first check what returns Debug.Print IsDate(beginLeave) ?

  14. #14
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Quote Originally Posted by Marc L View Post

    As a reminder Application.Match works in conjunction only with a Variant variable so easy to check via IsError & IsNumeric VBA functions
    without the need of an useless On Error Resume Next ...

    You should first check what returns Debug.Print IsDate(beginLeave) ?
    Returns true!!

  15. #15
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Error 0438 while using MATCH


    So the text date can be converted to a real date via the VBA function CDate.
    Then use a Variant variable to store the Application.Match result and check it via IsError or IsNumeric VBA function, that's all folks !

  16. #16
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    I tried to store the Application.Match result and got an overflow error... here's what I did, I probably screwed up

    Please Login or Register  to view this content.

  17. #17
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Error 0438 while using MATCH


    Attach at least a workbook, better for helpers than any guessing challenge ...

  18. #18
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Sorry here you go!
    Attached Files Attached Files

  19. #19
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,525

    Re: Error 0438 while using MATCH

    One thing I find is sometimes important to remember when Excel and VBA are talking to each other is that Excel only knows 2 data types: double precision float and text string. VBA, on the other hand, knows many other data types like currency and date. Therefore, the MATCH() function, being an Excel function, only knows 2 data types (double and string), and does not know what to do with a date data type, so it returns an error.

    I changed the statement to use a double:
    Please Login or Register  to view this content.
    (I'm not sure if this is always necessary, but it seemed necessary to first convert the text input to date before converting to double. CDbl(beginLeave) returned a type mismatch error suggesting that VBA could not figure out how to go from string direct to double). That seemed to allow the MATCH() function to return the expected row number for the date I would enter.

    When VBA is doing everything only using VBA functions, then you can take advantage of all of VBA's different data types. Sometimes, when I am using Excel functions or when VBA and Excel are talking to each other, I find it important to remember that Excel and its functions only know two data types, so it can be important to make sure that VBA is also using only those two data types.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  20. #20
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Error 0438 while using MATCH


    Works as well on my side with CLng & DateValue :

    PHP Code: 
    Sub Demo1()
        
    Dim V
            V 
    Application.InputBox(prompt:="When does the employee's maternity leave begin? Answer must be in MM/DD/YY format."Type:=2)
            If 
    Not IsDate(VThen Beep: Exit Sub
            V 
    Application.Match(CLng(DateValue(V)), [Calendar!B1:B366], 0)
            If 
    IsError(VThen Beep: Exit Sub
            Debug
    .Print V
    End Sub 

  21. #21
    Registered User
    Join Date
    08-25-2022
    Location
    Massachusetts
    MS-Off Ver
    2019
    Posts
    9

    Re: Error 0438 while using MATCH

    Thank you so much, Marc. I think CLng did the trick! No more errors of any sort!

+ 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: 6
    Last Post: 05-24-2022, 04:05 AM
  2. Replies: 2
    Last Post: 07-06-2020, 10:12 AM
  3. [SOLVED] Index,Match,Match based on date Range - error in some cells
    By jmont in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-26-2019, 04:47 AM
  4. 2D Index match match & error trapping
    By Mikeyabosbht in forum Excel General
    Replies: 4
    Last Post: 08-02-2018, 03:46 PM
  5. unable to get match property error in userform derived index match
    By alexcrofut in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-05-2015, 09:21 PM
  6. [SOLVED] .Match with On Error: On Error Resume Next works. On Error GoTo only works once. Err.Clear
    By Doc.AElstein in forum Excel - New Users/Basics
    Replies: 28
    Last Post: 03-16-2015, 12:55 PM
  7. [SOLVED] Vlookup to Pivot Table, using Match function, returns error if can't find match value
    By AndrewHowarth in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-16-2015, 12:10 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