【问题标题】:Excel - dynamically change the displayed digits after commaExcel - 在逗号后动态更改显示的数字
【发布时间】:2019-03-24 01:32:27
【问题描述】:

我想知道是否可以动态调整逗号后显示的数字,例如,如果我在单元格 A1 中有数字 1.245,并且我在单元格 B1 中写入“0.01”,则单元格 A1 会自动格式化为显示“1.25”,如果我在 A1 单元格 B1 中写“0.00001”,则显示“1.24500”。

请注意,我说的不是四舍五入,而是要显示的数字。

是否可以使用公式来做到这一点? 或者至少使用 VBA?

【问题讨论】:

    标签: excel digits


    【解决方案1】:

    你可以用 VBA 做到这一点:

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim numberFormatRange As Range
        Set numberFormatRange = Range("B1")
        If Not Intersect(Target, numberFormatRange) Is Nothing Then
            If IsNumeric(numberFormatRange) Then
                Range("A1").NumberFormat = Replace$(numberFormatRange.Value, "1", "0")
            End If
        End If
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 1970-01-01
      相关资源
      最近更新 更多