LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default VLookup function in VBA problem?

I would disagree with the categorization of my solution as a
workaround. I suspect that the belief that an explicit datatype
coercion is a workaround stems from the all the implicit type
conversions that both XL and VBA engage in -- so much so that when the
type conversion doesn't happen automatically, people get stuck.

Typically, one should recognize the fact that different functions work
with different datatypes. In those cases where the developer knows how
to coerce one data type into something else that is acceptable to a
function, it should be the responsibility of the developer to do so.

IMO, the software has no business doing implicit conversions.

In the OP's problem, we had a variable of the Date datatype, and a
function that required a double (or a string) for its argument. Since
we know that XL's dates are stored as numbers (i.e., XL has no date
datatype), it was safe to coerce the date into a double.

One of the benefits of VB.Net is the ability to use a 'Option Strict'
clause. This will require the developer to explicitly request every
datatype-to-datatype conversion; none will be automatic.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Bill:

I agree. It doesn't make complete sense to me either. Look at the
thread a little further down regarding: Can't Find Value.
It seems like the same problem involving passing values between VB and
XL using variables. Something in the object model seems inconsistent to
me, but it is more likely that I don't understand it as much as I would
like to.


Tushar's solution seems to be a good workaround to convert the variable
to a value by applying the type conversion function to the variable.

Bill Buckner wrote:
JWolf,

That makes sense except in the same worksheet function call I use another variable "insurance" which is defined in the following code. So if your response is the reason I keep getting "type" errors, why does it work for some and not for others? Could the fact that one is a date and one is an integer have anything to do with my problem? Maybe the fact that I do some calculations on the variable "insurance"

before it is sent to the worksheet function causes some type conversions to take place???

Dim insurance As Integer
Dim retireDate As Date
insurance = Range("Insurance_Selection")
retireDate = CDate(Range("Retire_Date_Primary").Value)

Application.VLookup(Range("Retire_Date_Primary"), Range("Pension_Table"), 21 + insurance - 1) '<= This works
Application.VLookup(retireDate , Range("Pension_Table"), 21 + insurance - 1) '<= This fails





 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with VLOOKUP function vsoler Excel Worksheet Functions 0 September 12th 09 04:06 PM
Combine VLOOKUP and IF function so #NA isn't returned as a value from VLOOKUP buffgirl71 Excel Discussion (Misc queries) 12 November 14th 06 11:36 PM
Problem with VLookUp Function Jelinek Excel Worksheet Functions 1 April 25th 06 03:04 PM
Vlookup Function Problem Parker Excel Worksheet Functions 3 January 13th 05 06:53 PM
VLookup function in VBA problem? Bill Buckner Excel Programming 0 May 11th 04 07:41 PM


All times are GMT +1. The time now is 09:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"