Results 1 to 10 of 10

Thread: Match Function Problem!!! (RESOLVED)

  1. #1

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Match Function Problem!!! (RESOLVED)

    VBA Excel

    I keep getting an Error 2042 returned by the match function here. I have carfully set my Range variables to the correct columns and rows. The range objects are all dates. It seems no matter what I do I get that error. Any ideas? Here is the code:

    Code:
    Sub test()
        Dim matchstart As Range
        Dim matchend As Range
        Dim matchRange As Range
    
        c = CDate("1/28/2004")
    
        Set matchstart = Workbooks("datafile.xls").Sheets("futexpiry").Cells(2, 5)
        Set matchend = Workbooks("datafile.xls").Sheets("futexpiry").Cells(500, 5)
        Set matchRange = Workbooks("datafile.xls").Sheets("futexpiry").Range(matchstart, matchend)
        FirstMatch = Application.Match(c, matchRange, 1)
    End Sub
    Last edited by Avatarp; Feb 9th, 2004 at 05:35 PM.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Where do you Dim c?

  3. #3

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Salvelinus...

    I actually don't have to Dim anything.

  4. #4
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Well, that's not a good idea...
    Anyway, MSDN has two types of listings for error 2042. One is ResourceNameSuffixTooLong, the other is a SQL error. Are you sure the error is coming in that code? Try stepping through it.
    Or look here.

  5. #5

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    stepping through

    I have been staring at this problem for a while now. stepping through it FirstMatch = error 2042

  6. #6

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    looking at other peoples problem...

    I know that 1/28/2004 is in the range I assigned. So shouldn't this be a no brainer lol...

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Try msgboxing your values before you hit FirstMatch, make sure they're what you think they area. I don't work much with Excel.

  8. #8

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Add Watch...

    I added a watch on the values so I can see what they are.

  9. #9
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    Try this Google thread. Seems to discuss your problem. At a glance, looks like it's not finding c.

  10. #10

    Thread Starter
    Fanatic Member Avatarp's Avatar
    Join Date
    Sep 2002
    Location
    Calgary
    Posts
    826

    Thanks salvelinus...

    I've looked at that string and many more but it just came to me. When working with dates I should convert any of those date variables to Doubles. Even though the Spreadsheet Range shows dates in Date Format they are actually Numbers. Thanks for helping me out here. I think I got it now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width