Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL: Decimal values in Cell Not Being Picked Up 2

Status
Not open for further replies.

mmignot

Programmer
Jul 16, 2001
44
0
0
US
Hello all,

I am attempting to use VBA code to read certain cells on a worksheet. I'm having trouble getting the decimal values of in cells with amounts. For example, a cell has the value 1,000.53. When I use the following code to retrieve the cell value:

Code:
' *----------------------------------*
' * Retrieve deductible amount.      *
' *----------------------------------*
' *
   Deduct_AMT = Range("E20").Select
   Deduct_AMT = ActiveCell.Value

This code will bring back a value of 1,000, even though in the cell the value specified is 1,000.53. I need to get the exact value in the cell. The variable "Deduct_AMT" is defined as "Long".

Anyone have any thoughts or suggestions?

Many thanks!

 
Well, for starters the variable "Long" is short for Long integer.

The line Deduct_AMT = Range("E20").Select doesn't do exactly what you probably think you are doing.

Just use Deduct_AMT = Range("E20").value
 
Change the variable definition from Long to Single, Double, or Currency depending on the values you expect and the precision you need. A Long integer will truncate any fractional part of a number.
 


Code:
dim Deduct_AMT as currency
Deduct_AMT = Range("E20").Value
No need & undesirable in most cases, to use the Select method.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Many thanks to all for your suggestions. I defined the amount variables as "Double", also now just using the following:

Code:
' *----------------------------------*
' * Deduct Amount.                   *
' *----------------------------------*
' *
   Deduct_AMT = Range("E20").Value

Thanks again!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top