Solved

vb 6.0  -->  In vb code, VLookup using Application.WorksheetFunction.VLookup() returning 82.00 instead of 82.327, 75.00 instead of 75.728 ..  etc..

Posted on 2008-10-26
5
543 Views
Last Modified: 2011-10-03
In vb 6, I'm doing a VLookup which references an excel range...    using Application.WorksheetFunction.VLookup(parmInvestName, rngFind, 1, False)  , but it keeps returning the whole # without the decimal..    but i need the decimal.

This is urgent question as I'm not very familiar with vb syntax..   i've tried changing from Double to Long and everything else, but it still doesn't return the decimal places for a double type..  here is example of one of my attempts  :  

Public Function FindPutDeltaRefSecond(parmInvestName As String) As Long
    Dim rngFind As Range
    Set rngFind = RefData.Option.TablePutData
    On Error GoTo Terminate
    FindPutDeltaRefSecond = CLng(Application.WorksheetFunction.VLookup(parmInvestName, rngFind, 3, False))
Terminate:
    Set rngFind = Nothing
End Function
0
Comment
Question by:lblinc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Author Comment

by:lblinc
ID: 22808862
I tried using different combinations using   CDbl, CLng, and then trying to Format(x, "#00.00") the Double as a string..  still nothing but zeroes to the right of decimal is returned.    In the spreadsheet, the numbers I'm doing the VLookup to retrieve look like this ...  

90.662
82.327
75.728
69.252
48.399
36.910
30.355
17.092

Instead I keep getting this returned in VLookup..

90.000
82.000
75.000
69.000
..
..






0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 22808883
To confirm and no offence meant ...

When producing as a double you set both the return type and the conversion to double?

Public Function FindPutDeltaRefSecond(parmInvestName As String) As Double
...
    FindPutDeltaRefSecond = CDbl(Application.WorksheetFunction.VLookup(parmInvestName, rngFind, 3, False))

Chris
0
 

Author Comment

by:lblinc
ID: 22808926
Yean I know what you're saying, i've tried everything..     i thought maybe for some reason the input retrieved from spreadsheet possibly was read in as a string..    I've tried multiple combinations to try to get the correct data when debugging..
0
 

Author Comment

by:lblinc
ID: 22808956
Finally got it, thanks for a bit of input chris..
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22810419
For the record, what was the issue ... it will help others in the future?

Chris
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Put text in a picture ASP.NET C# 2 73
Looking for VB6 code to read SQL table export it to ascii 8 61
MsgBox 4 76
VBA: copy range dynamically based on config sheet v3 6 54
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question