|
-
Feb 9th, 2004, 01:26 PM
#1
Thread Starter
Fanatic Member
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.
-
Feb 9th, 2004, 02:03 PM
#2
Frenzied Member
-
Feb 9th, 2004, 02:04 PM
#3
Thread Starter
Fanatic Member
Salvelinus...
I actually don't have to Dim anything.
-
Feb 9th, 2004, 03:46 PM
#4
Frenzied Member
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.
-
Feb 9th, 2004, 03:57 PM
#5
Thread Starter
Fanatic Member
stepping through
I have been staring at this problem for a while now. stepping through it FirstMatch = error 2042
-
Feb 9th, 2004, 03:58 PM
#6
Thread Starter
Fanatic Member
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...
-
Feb 9th, 2004, 04:36 PM
#7
Frenzied Member
Try msgboxing your values before you hit FirstMatch, make sure they're what you think they area. I don't work much with Excel.
-
Feb 9th, 2004, 04:42 PM
#8
Thread Starter
Fanatic Member
Add Watch...
I added a watch on the values so I can see what they are.
-
Feb 9th, 2004, 04:46 PM
#9
Frenzied Member
Try this Google thread. Seems to discuss your problem. At a glance, looks like it's not finding c.
-
Feb 9th, 2004, 05:22 PM
#10
Thread Starter
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|