+ Reply to Thread
Results 1 to 6 of 6

Error 2042 while comparing dates

  1. #1
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Error 2042 while comparing dates

    Hi experts and gurus,

    I have a created a Maturity Date Slicer and written a VBA code to select maturity dates that falls within 30 days after a month end.

    The code is as under:

    Please Login or Register  to view this content.
    The date in the Worksheet ("30Days") is translated by following formula "Text(Value,"DD-MMM-YYYY")", whereas the maturity date in the source worksheet is also in the same data format.

    While running the macro code I am getting error 2042. The error is in "If IsNumeric(x)" line. I am researching to change this statement for more than 2 hours but with no success. Can somebody help me to fix this line and come up with the solution?

    Thank you
    Roshan Shakya

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

    Re: Error 2042 while comparing dates

    It is going to be difficult for us to help debug this with only the code to work with. Can you upload a sample file?

    Error 2042 is the #N/A error returned when Match() does not find a match. I see two possible meanings to fixing this error.

    Do you mean that you need help with error trapping the error so that your procedure will know what to do when match does not find a match? If this is what you mean, then your procedure needs an additional If..End If block that will deal with the error.

    Or do you mean that you are certain that it should find a match, and you are trying to figure out why it is not finding a match? If this is what you mean, then you will need to look very carefully (using watches or the immediate window or other debugging tool ) to see exactly what is in slItem.Name and what is in column A of sheet "30days" and make absolutely sure that they are the same. If you are unfamiliar with VBA's debugging tools: http://www.cpearson.com/excel/DebuggingVBA.aspx
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Error 2042 while comparing dates

    Thanks MrShorty,

    I have attached the file for your reference.

    Thank you
    Roshan Shakya
    Attached Files Attached Files

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Error 2042 while comparing dates

    Issue here is that A1 is also =TEXT()

    So when you are adding to A1 column B values, depending on region setting it will return #Value Error.

    In A1, have valid date value, and format as dd-mm-yyyy.

    Also, to avoid updating PivotTable during every iteration of loop, code modified to below.
    Please Login or Register  to view this content.
    See attached.

    Though personally, I'd recommend utilizing OLAP based Pivot Table.
    Attached Files Attached Files
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  5. #5
    Forum Contributor
    Join Date
    05-13-2019
    Location
    Halifax, Canada
    MS-Off Ver
    2016
    Posts
    176

    Re: Error 2042 while comparing dates

    Thanks CK76 for the suggestion and in fact the solution.

    Kind regards,
    Roshan Shakya

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,885

    Re: Error 2042 while comparing dates

    You are welcome and thank for the rep

    If your query is answered. Please mark the thread as solved using thread tool found at top of your initial post.

+ 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] For Loop: Error 2042
    By VAer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-21-2017, 11:03 AM
  2. [SOLVED] Error 2042 for application.match
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2016, 03:41 AM
  3. VBA Blookup Error 2042
    By SamuelJackson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-10-2014, 08:59 PM
  4. Error 2042 with Application.Match
    By mgurren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2013, 02:15 AM
  5. [SOLVED] Error 2042
    By GreenTee in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-26-2013, 12:27 AM
  6. Error 2042
    By magix in forum Excel General
    Replies: 3
    Last Post: 12-12-2005, 08:20 PM
  7. Error 2042-how I was told to do it.
    By papa jonah in forum Excel General
    Replies: 2
    Last Post: 04-11-2005, 10:08 PM

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