Serving the Quantitative Finance Community

 
User avatar
AAD
Topic Author
Posts: 1
Joined: December 14th, 2006, 9:43 am

VLookup VBA Run-time Error '13': Type Mismatch

January 3rd, 2007, 5:21 pm

Hi everyone,I am trying to use VLookup in my VBA code:Application.VLookup(Dates(i), Worksheets("XMKT").Range(Cells(8, 33), Cells(1007, 35), 3), but it gives me the following error message:Run-time Error '13': Type mismatch What am I doing wrong?Please help.Artour
Last edited by AAD on January 2nd, 2007, 11:00 pm, edited 1 time in total.
 
User avatar
cemil

VLookup VBA Run-time Error '13': Type Mismatch

January 4th, 2007, 9:19 am

I think you have a lack of ")" on your function
 
User avatar
AAD
Topic Author
Posts: 1
Joined: December 14th, 2006, 9:43 am

VLookup VBA Run-time Error '13': Type Mismatch

January 5th, 2007, 9:33 am

Thanks for your reply. Unfortunately, the problem still remains....
 
User avatar
cemil

VLookup VBA Run-time Error '13': Type Mismatch

January 5th, 2007, 9:59 am

I test your fonction but it run without problems.Can you show your VBA function to look at.
 
User avatar
MMP
Posts: 1
Joined: August 18th, 2005, 1:18 am

VLookup VBA Run-time Error '13': Type Mismatch

January 7th, 2007, 2:55 am

1. Is the Dates() array dimensioned as a date? Is the Lookup column 33 (AG) a list of dates as well? If so, Excel will use the Long Integer representation. Coercing the lookup value to long worked for me...x = Application.VLookup(CLng(Dates(i)), Worksheets("XMKT").Range(Cells(8, 33), Cells(1007, 35)), 3)2. Your code will likely fail if the active sheet is not "XMKT" because the Cells(x,y) references are not fully qualified. Do something like the following to make it more robust...'''''''''''''''''''''''''''''''''''''''Sub test()Dim x, i, Dates(1 To 1) As DateDim TestRng As RangeWith ThisWorkbook With .Worksheets("XMKT") Set TestRng = .Range(.Cells(8, 33), .Cells(1007, 35)) End WithEnd Withi = 1Dates(1) = DateSerial(2006, 1, 15)x = Application.VLookup(CLng(Dates(i)), TestRng, 3)MsgBox xEnd Sub'''''''''''''''''''''''''''''''''''''''''''
Last edited by MMP on January 6th, 2007, 11:00 pm, edited 1 time in total.