PC Review


Reply
Thread Tools Rate Thread

cell has decimal value returns whole number, why?

 
 
jamby
Guest
Posts: n/a
 
      25th Jun 2007
HI

New to VB and trying to write a program that gets two values from
cells and calculates a column of values.

cell "C19" = 4.0938

cell "C21" = 4.8438
=========================
Sub FillInRange()

Dim intK As Long
Dim intT As Long
Dim intX As Long
Dim intY As Long

intX = Range("C19").Value
intY = Range("C21").Value
intT = Range("C15").Value
Range("L28").Select

For I = 1 To (intT - 1) Step 1
intK = intX + (intY * I)
Selection.Value = intK
ActiveCell.Offset(1, 0).Select
Next

End Sub
=======================

But in the program they appear as C19 = 4 C21 = 5
Is there a way to get the decimal value into the variables?

Sorry if this dosen't make to much sense as I am not sure of the terms
to use.
Jim

 
Reply With Quote
 
 
 
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      25th Jun 2007
> New to VB and trying to write a program that gets two values from
> cells and calculates a column of values.
>
> cell "C19" = 4.0938
>
> cell "C21" = 4.8438
> =========================
> Sub FillInRange()
>
> Dim intK As Long
> Dim intT As Long
> Dim intX As Long
> Dim intY As Long
>
> intX = Range("C19").Value
> intY = Range("C21").Value
> intT = Range("C15").Value
> Range("L28").Select
>
> For I = 1 To (intT - 1) Step 1
> intK = intX + (intY * I)
> Selection.Value = intK
> ActiveCell.Offset(1, 0).Select
> Next
>
> End Sub
> =======================
>
> But in the program they appear as C19 = 4 C21 = 5
> Is there a way to get the decimal value into the variables?


Although you say C19=4 and C21=5, I am guessing your complaint is intX=4 and
intY=5 because of your last sentence above. If that is the case, the problem
is you declared these variables as Longs... a Long can only hold whole
numbers. Declare them as Single or Double, depending on precision
requirements and, assuming I am right in my assumptions, all should be as
you want it.

Rick

 
Reply With Quote
 
jamby
Guest
Posts: n/a
 
      25th Jun 2007
On Jun 24, 7:15 pm, "Rick Rothstein \(MVP - VB\)"
<rickNOSPAMn...@NOSPAMcomcast.net> wrote:

> Although you say C19=4 and C21=5, I am guessing your complaint is intX=4 and
> intY=5 because of your last sentence above. If that is the case, the problem
> is you declared these variables as Longs... a Long can only hold whole
> numbers. Declare them as Single or Double, depending on precision
> requirements and, assuming I am right in my assumptions, all should be as
> you want it.
>
> Rick



Yes, Thanks that fixed the problem. Values are now what I wanted..
Jim

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format for Whole number and 1 Decimal in same Cell Sean Microsoft Excel Worksheet Functions 4 30th Nov 2007 01:44 PM
number returns only two decimal places after I change from text =?Utf-8?B?cXVhbGU=?= Microsoft Excel Misc 5 8th Dec 2005 08:22 PM
How do I insert 2 decimal places to a number in cell? =?Utf-8?B?UmViZWNjYSBNYXJ0aW5leg==?= Microsoft Excel Worksheet Functions 6 7th Jul 2005 07:12 PM
I want to format a number cell without the decimal and without ro. =?Utf-8?B?TEFN?= Microsoft Excel Misc 8 20th Apr 2005 04:59 PM
CONVERT HEXADECIMAL CELL TO DECIMAL NUMBER =?Utf-8?B?SkFZ?= Microsoft Excel Worksheet Functions 4 25th Jan 2005 02:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:13 PM.