ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Cutting off numbers to two decimal places using a SCRIPT (https://www.excelbanter.com/excel-programming/306093-cutting-off-numbers-two-decimal-places-using-script.html)

tilt64

Cutting off numbers to two decimal places using a SCRIPT
 
Hi, I would like to know if any of you would know how to change the cel
contents in the following situation:
I enter 2.1342
I want excel to change it to 2.13
not just changing the formatting, but actually changing the number t
round to the hundreths place. When I go back to that cell, I don'
want to know that there was ever a number there besides 2.13, does tha
make sense? I want it to edit my number for me.
Thanks ahead of time,
We

--
Message posted from http://www.ExcelForum.com


Nigel

Cutting off numbers to two decimal places using a SCRIPT
 
Two choices

1. Either put a formula into a target cell on the worksheet referencing the
cell with the source

Range("D2").Formula = "=ROUND(B2,2)"

2. Or in program use

YourNumber = Round(YourNumber, 2)

Cheers
Nigel

"tilt64 " wrote in message
...
Hi, I would like to know if any of you would know how to change the cell
contents in the following situation:
I enter 2.1342
I want excel to change it to 2.13
not just changing the formatting, but actually changing the number to
round to the hundreths place. When I go back to that cell, I don't
want to know that there was ever a number there besides 2.13, does that
make sense? I want it to edit my number for me.
Thanks ahead of time,
Wes


---
Message posted from http://www.ExcelForum.com/




JE McGimpsey

Cutting off numbers to two decimal places using a SCRIPT
 
You can do it without VBA if you choose Tools/Options/Calculation and
check the Precision as displayed checkbox. However that's a global
setting for the workbook, so you may not want to use that.

If the value is a result of a calculation, wrap the calc with ROUND:

=ROUND(<your calc here,2)

Using VBA, if the entry is made manually or remotely, put this in the
worksheet code module:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
Application.EnableEvents = False
With Range("A1")
.Value = Application.Round(.Value, 2)
End With
Application.EnableEvents = True
End If
End Sub



In article ,
tilt64 wrote:

Hi, I would like to know if any of you would know how to change the cell
contents in the following situation:
I enter 2.1342
I want excel to change it to 2.13
not just changing the formatting, but actually changing the number to
round to the hundreths place. When I go back to that cell, I don't
want to know that there was ever a number there besides 2.13, does that
make sense? I want it to edit my number for me.
Thanks ahead of time,
Wes



All times are GMT +1. The time now is 01:56 PM.

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