+ Reply to Thread
Results 1 to 6 of 6

Modify DateTime for Application.Match - error 2042

  1. #1
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Modify DateTime for Application.Match - error 2042

    Please Login or Register  to view this content.

    If I remove where I highlighted in orange , "RowNumber" returns the correct position (which is "5").

    My dates and time are mint. It's how I am trying to use Application.Match with the fact that I am trying to modify my date and time (e.g. "1/4/2016 3:00 AM") which is screwing it up?

    Any ideas?

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

    Re: Modify DateTime for Application.Match - error 2042

    Impossible to tell without more information.

    try breaking down your code and see where your fault lies.

    [CODE]
    D1 =w ' D1 should be a number ie 5 not "5". If it is "5" then modify to "5" *1

    D2 = OpenTime_modified = Int(Cells(x, 4).Value 'D2 should be a Time "00:05:00"

    D3 = OpenTime_modified = Int(Cells(x, 4).Value + TimeSerial(0 + w, 0, 0)) 'D3 should be a should be a Time "00:05:00" a date and time "22/05/2015 00:05:00"


    When you are trying to perform a match, you say your match works before you add Timeserial.
    So I assume it cannot be a mismatch due to your Data being stored in Excel as Numbers and your OpenTime being stored in VBA as String. As suggested by Jindon below:

    [/CODE
    Last edited by mehmetcik; 05-21-2016 at 05:50 AM.
    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.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,579

    Re: Modify DateTime for Application.Match - error 2042

    Have you tried
    Please Login or Register  to view this content.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Modify DateTime for Application.Match - error 2042

    I don't follow what you are asking, what "mint" dates and Times are, or what your data configuration is. I do notice two things.


    OpenTime_modified = Int(Cells(x, 4).Value + TimeSerial(0 + w, 0, 0))

    The Int function will strip the Time value. An integer is just a date with no time. So OpenTime_modified will be just a date with no time.



    RowNumber = Application.Match(OpenTime_modified, Range("DateTime"), 0)

    In your code, the Match function is missing the Match-type argument.
    Syntax

    MATCH(lookup_value,lookup_array,match_type)
    • Lookup_value is the value you use to find the value you want in a table.
    • Lookup_value is the value you want to match in lookup_array. For example, when you look up someone's number in a telephone book, you are using the person's name as the lookup value, but the telephone number is the value you want.


    Lookup_value can be a value (number, text, or logical value) or a cell reference to a number, text, or logical value.

    Lookup_array is a contiguous range of cells containing possible lookup values. Lookup_array must be an array or an array reference.

    • Match_type is the number -1, 0, or 1. Match_type specifies how Microsoft Excel matches lookup_value with values in lookup_array.
    • If match_type is 1, MATCH finds the largest value that is less than or equal to lookup_value. Lookup_array must be placed in ascending order: ...-2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE.
    • If match_type is 0, MATCH finds the first value that is exactly equal to lookup_value. Lookup_array can be in any order.
    • If match_type is -1, MATCH finds the smallest value that is greater than or equal to lookup_value. Lookup_array must be placed in descending order: TRUE, FALSE, Z-A, ...2, 1, 0, -1, -2, ..., and so on.
    • If match_type is omitted, it is assumed to be 1.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  5. #5
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Modify DateTime for Application.Match - error 2042

    Thank you all for your valued feedback.

    I have put together this video that walks through my code to help answer some of the points raised by all those that have posted so far: http://screencast.com/t/U0gdgxoDa7j

    Don't go at me too hard though; i've only delved into VBA yesterday! :P

  6. #6
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Modify DateTime for Application.Match - error 2042

    UPDATE: I worked out what I was doing wrong:

    Please Login or Register  to view this content.
    I need to declare "OpenTime_modified" as a "double". Now the Application.Match() function pulls it back correctly.

    Thanks to everyones input though

+ 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] Error 2042 for application.match
    By a.hudrea in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2016, 03:41 AM
  2. Error 2042 on Application.Match formula
    By krazyhype19 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-05-2015, 03:25 AM
  3. [SOLVED] Error 2042 using Application.Match to add item and update combobox list
    By newbi004 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-14-2013, 07:55 AM
  4. [SOLVED] Application.Match returns Error 2042 whene text absolutely does exist?
    By Rhudi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2013, 04:21 PM
  5. Error 2042 with Application.Match
    By mgurren in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-08-2013, 02:15 AM
  6. [SOLVED] Error 2042 with application.vlookup for date
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 03:57 AM
  7. Error 2042
    By magix in forum Excel General
    Replies: 3
    Last Post: 12-12-2005, 08:20 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