下面是代码,我希望删除小数但保留值-是否有简单的方法来替换或删除小数“#0.00”但仍保留值?
Dim lCheckAmtCol As Double
Dim lNumCols As Long
' Get user-supplied values used in this procedure
With Sheet1
lCheckAmtCol = .Range("rSourceCheckAmtCol").Value
End With
' Copy source column with check amount data to next empty column and format values as numbers with two decimal places
With Worksheets(sSourceSheetName)
lNumCols = .Cells(lSourceFirstRow, lSourceFirstCol).CurrentRegion.Columns.Count
.Columns(lCheckAmtCol).Copy
.Cells(1, lNumCols + 1).PasteSpecial Paste:=xlPasteValues
.Cells(1, lNumCols + 1).EntireColumn.NumberFormat = "#0.00"
End With
End Sub
答案 0 :(得分:0)
替换或删除小数点“#0.00”,但仍保留该值
此行中将应用格式:
.Cells(1, lNumCols + 1).EntireColumn.NumberFormat = "#0.00"
简单地将其注释掉:
'.Cells(1, lNumCols + 1).EntireColumn.NumberFormat = "#0.00"
如果您是说“我想要不显示小数的数字”,请执行以下操作:
.Cells(1, lNumCols + 1).EntireColumn.NumberFormat = "#0"
答案 1 :(得分:0)
以下内容将删除Sheet1的单元格A1中的小数点分隔符
With Worksheets("Sheet1")
.Range("A1").Value = CLng(Replace$(.Range("A1").Value, Application.DecimalSeparator, vbNullString))
End With
因此123.456
将成为123456
。如果您需要在多个单元格中执行此操作,则必须使用循环。