+ Reply to Thread
Results 1 to 5 of 5

WorksheetFunction.Match gives Error 1004

  1. #1
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    WorksheetFunction.Match gives Error 1004

    I've been tearing my hair out for 2 days trying to figure out why I keep getting an Error 1004 (Unable to get the Match property of the WorksheetFunction class) with this code:
    Please Login or Register  to view this content.
    Here are the debug results from the Intermediate window:
    EndDate - 6 = 3/24/2018
    EndDate = 3/30/2018
    SearchRange.Address = $C$305:$C$627

    EndDate is a named range (with Date format) in ThisWorkbook (which is the active workbook). SearchRange is declared As Range and is set to a range in another (open) workbook, and all the cells in that range are in Date format. The address of SearchRange is correct, and it refers to the correct worksheet. DateStartRow is declared As Long.

    If I go to the worksheet that includes SearchRange and enter the MATCH formula by hand [=MATCH(E9,$C$305:$C$627,1), where cell E9 contains the date 3/24/18], it works fine. But every time I run the macro, I get Error 1004. Help!!

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WorksheetFunction.Match gives Error 1004

    Perhaps this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    03-26-2015
    Location
    Cookeville, TN
    MS-Off Ver
    Excel 365
    Posts
    202

    Re: WorksheetFunction.Match gives Error 1004

    It worked! Thanks!!!

    Can you explain why converting to a Long value works, when I'm looking for a date? And why a manually-entered MATCH formula (using a date-formatted lookup value) works, but the VBA code (using a date) doesn't?

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: WorksheetFunction.Match gives Error 1004

    Dates and VBA are always problematic- especially if you live somewhere that doesn't use mm/dd/yyyy format (i.e. everywhere but the US!). Converting them to simple number values is usually the solution.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: WorksheetFunction.Match gives Error 1004

    I use Application.Match rather than Worksheetfunction.Match.

    If the value isn't there, Application.Match will return an error value, but WorksheetFunction.Match will cause a VBA error and crash the routine.

    For example, this can crash if WorksheetFunction.Match is used in place of Application.Match
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. Runtime error 1004 with Application.Worksheetfunction.Match
    By jeetkapadia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-14-2017, 12:46 PM
  2. [SOLVED] WorksheetFunction.match run time error '1004' with numbers but not text
    By Hussar13 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2013, 05:31 PM
  3. Run-time error '1004': Unable to get the Match property of Worksheetfunction class
    By krish T in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-27-2010, 10:04 PM
  4. Run-time error 1004: Unable to get the Match property of the WorksheetFunction class
    By maffmommie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2010, 09:32 AM
  5. worksheetfunction.match giving run time error '1004'
    By devo2511 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2010, 04:47 PM
  6. run-time error '1004 Unable to get Match property of WorksheetFunction class
    By exl044 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2010, 02:23 AM
  7. Runtime error 1004 with use of WorksheetFunction
    By Johny027 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-15-2009, 06:02 AM

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