ExcelBanter

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

[email protected][_2_]

rounding
 
Hi, Iv assigned a value in vba to MyValue, Can somebody advise how I
round this up if the decimal is 0.5 or above, or down if below 0.5.
Regards Robert


K Dales[_2_]

rounding
 
MyRoundedValue=Round(MyValue,0)
--
- K Dales


" wrote:

Hi, Iv assigned a value in vba to MyValue, Can somebody advise how I
round this up if the decimal is 0.5 or above, or down if below 0.5.
Regards Robert



Dave Peterson

rounding
 
VBA's Round (added in xl2k) works differently from Excel's =Round().

You may want to stick with Excel's:

Option Explicit
Sub testme()

Dim myValue As Double
Dim iCtr As Long

For iCtr = 1 To 4
myValue = iCtr + 0.5
MsgBox "myValue=" & myValue & _
vbLf & "Round=" & Round(myValue, 0) & _
vbLf & "Application.Round=" & Application.Round(myValue, 0)
Next iCtr

End Sub



wrote:

Hi, Iv assigned a value in vba to MyValue, Can somebody advise how I
round this up if the decimal is 0.5 or above, or down if below 0.5.
Regards Robert


--

Dave Peterson


All times are GMT +1. The time now is 01:18 AM.

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