ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   prevent rounding up (https://www.excelbanter.com/excel-programming/356944-prevent-rounding-up.html)

jhahes[_51_]

prevent rounding up
 

I am exporting external data from a database into excel.

There are 3 columns full of data that are exported into excel as tex
format.

They are A, C and D

The problem I am having right now is that when I export the dat
everything works however, when I run the following code it is changin
exported data in a cell i.e.(4.75) to 5. Is there anyway to have thi
remain the same without rounding up.

Here is my code:

Do
ActiveCell.Value = CDbl(ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = ""
Dim LastRowWithItemNumber As Integer
LastRowWithItemNumber = ActiveCell.Row - 1
Dim cell As Range
Range("C2").Select
For Each cell In Range("C2:D" & LastRowWithItemNumber)
If cell.Value < "" Then cell.Value = CLng(cell.Value)
Next
MsgBox "Update Finished

--
jhahe
-----------------------------------------------------------------------
jhahes's Profile: http://www.excelforum.com/member.php...fo&userid=2359
View this thread: http://www.excelforum.com/showthread.php?threadid=52579


Gary L Brown

prevent rounding up
 
If cell.Value < "" Then cell.Value = CLng(cell.Value)

Definition of CLng:
-2,147,483,648 to 2,147,483,647; fractions are rounded.

Change your type!
--
Gary Brown

If this post was helpful, please click the ''Yes'' button next to ''Was this
Post Helpfull to you?''.


"jhahes" wrote:


I am exporting external data from a database into excel.

There are 3 columns full of data that are exported into excel as text
format.

They are A, C and D

The problem I am having right now is that when I export the data
everything works however, when I run the following code it is changing
exported data in a cell i.e.(4.75) to 5. Is there anyway to have this
remain the same without rounding up.

Here is my code:

Do
ActiveCell.Value = CDbl(ActiveCell.Value)
ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = ""
Dim LastRowWithItemNumber As Integer
LastRowWithItemNumber = ActiveCell.Row - 1
Dim cell As Range
Range("C2").Select
For Each cell In Range("C2:D" & LastRowWithItemNumber)
If cell.Value < "" Then cell.Value = CLng(cell.Value)
Next
MsgBox "Update Finished"


--
jhahes
------------------------------------------------------------------------
jhahes's Profile:
http://www.excelforum.com/member.php...o&userid=23596
View this thread: http://www.excelforum.com/showthread...hreadid=525795




All times are GMT +1. The time now is 12:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com