Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default String to Rounded Integer

I'm trying to make some cell values integers. The database saves the
fractions as a string and I can't seem to get them to convert to integers so
that I can round them.

What I'd like:
0.135450617647059 (string)
to
0.135 (integer or string... guess I don't really care)

What I've tried:
x = Round(Val(ActiveSheet.Cells(brow, "K")), 3)
y = Round(ActiveSheet.Cells(crow, "J"), 3)

I've tried using Val and CInt and they didn't work for me. Any suggestions?
Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 192
Default String to Rounded Integer

Now that I think about it, it would be best to convert it to an integer so
that I can round. Thanks!

"StumpedAgain" wrote:

I'm trying to make some cell values integers. The database saves the
fractions as a string and I can't seem to get them to convert to integers so
that I can round them.

What I'd like:
0.135450617647059 (string)
to
0.135 (integer or string... guess I don't really care)

What I've tried:
x = Round(Val(ActiveSheet.Cells(brow, "K")), 3)
y = Round(ActiveSheet.Cells(crow, "J"), 3)

I've tried using Val and CInt and they didn't work for me. Any suggestions?
Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default String to Rounded Integer

this works for me, wit a test srting in A1.

Sub test()
Dim num As Double
num = Round(Val(Range("A1")), 3)
MsgBox num
End Sub


--


Gary


"StumpedAgain" wrote in message
...
I'm trying to make some cell values integers. The database saves the
fractions as a string and I can't seem to get them to convert to integers so
that I can round them.

What I'd like:
0.135450617647059 (string)
to
0.135 (integer or string... guess I don't really care)

What I've tried:
x = Round(Val(ActiveSheet.Cells(brow, "K")), 3)
y = Round(ActiveSheet.Cells(crow, "J"), 3)

I've tried using Val and CInt and they didn't work for me. Any suggestions?
Thanks!




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default String to Rounded Integer

On Wed, 11 Jun 2008 11:21:01 -0700, StumpedAgain
wrote:

Now that I think about it, it would be best to convert it to an integer so
that I can round. Thanks!


If you convert it to an integer, you will lose everything after the decimal!
And Integer variables are stored as 16-bit (2-byte) numbers ranging in value
from -32,768 to 32,767. This may be limiting.

See Gary's solution.
--ron
Reply
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
convert string to integer eugene Excel Programming 7 February 20th 07 07:00 PM
Varaibles as both integer and String RominallL Excel Programming 5 January 31st 07 06:33 PM
String or integer? JustinP Excel Programming 2 September 5th 06 06:56 AM
Compare string with integer hurriance[_8_] Excel Programming 2 June 26th 06 09:14 AM
Concatenating a string and an integer [email protected] Excel Programming 2 April 5th 06 07:40 PM


All times are GMT +1. The time now is 02:46 PM.

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

About Us

"It's about Microsoft Excel"