简体   繁体   English

如何在excel 2016中动态舍入一组单元格的单元格值

[英]How to dynamically round off cell value for group of cell in excel 2016

I have excel template file which is excel 2016 , I want from Column E23 to E100 if some one enter any value it round off till 3 digit .我有一个 excel 模板文件,它是 excel 2016,如果有人输入任何值,我想要从 E23 列到 E100,它四舍五入到 3 位数字。 Example :- 12345.123456 should convert to 12345.123 .示例:- 12345.123456 应转换为 12345.123。

Bu this should only effective to that cell where any value get change .但这应该只对任何值发生变化的单元格有效。 In attached picture Column E is where I want round off .在附图中,E 列是我想要四舍五入的地方。 Any help will be greatly appreciated .任何帮助将不胜感激 。

在此处输入图片说明

Try this:尝试这个:

To enter this event-triggered Macro, right click on the sheet tab.要输入此事件触发的宏,请右键单击工作表选项卡。 Select "View Code" from the right-click drop-down menu.从右键单击下拉菜单中选择“查看代码”。 Then paste the code below into the window that opens.然后将下面的代码粘贴到打开的窗口中。


Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim C As Range

If Not Intersect(Target, Columns(5)) Is Nothing Then
    Application.EnableEvents = False
    For Each C In Intersect(Target, Columns(5))
        If IsNumeric(C.Value) And Len(C.Value) > 0 Then
            C.Value = Round(C.Value, 3)
        End If
    Next C
End If
Application.EnableEvents = True

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM