Excel vba 2个小数点或整个表格的小数点数

时间:2016-04-29 08:32:35

标签: excel vba

有没有办法在2点或2位数后删除小数值

我试过下面的代码,显示已经改变,但是单元格值只有十进制

Selection.NumberFormat = 0#

示例值 - 212582.397228849

3 个答案:

答案 0 :(得分:1)

您可以通过以下方式更改任何特定列的格式:

Range("A1").EntireColumn.NumberFormat = "#.00" '---> here Column is A

或者,如果您想更改范围的格式:

Sub rounding()
    Dim r As Range
    Set r = ActiveWorkbook.Worksheets("Sheet1").Range("A1:E20") '--->enter your range here
    r.NumberFormat = "#0.00"
    ActiveWorkbook.PrecisionAsDisplayed = True
End Sub

答案 1 :(得分:0)

ActiveWorkbook.PrecisionAsDisplayed = True之后添加这段代码 改变格式然后它工作正常

谢谢你们

Sub rounding()
    Dim r As Range
    Set r = ActiveWorkbook.Worksheets("Sheet1").Range("A1:E20") '--->enter your range here
    r.NumberFormat = "#0.00"
ActiveWorkbook.PrecisionAsDisplayed = True 
end sub

答案 2 :(得分:0)

尝试以下

Sub decimalcheck()
    Dim a As Integer
    Debug.Print Format(Range("G3").Value, "#.00")
End Sub