VBA用逗号替换点

时间:2017-06-14 13:24:29

标签: excel vba excel-vba

我刚开始使用VBA开发宏。使用我的宏

用逗号替换圆点时遇到一些麻烦

我试过这些代码:

Dim Cell As Range

For Each Cell In Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, Cells(1, Columns.Count).End(xlToLeft).Column))
  Cell.Value = Application.WorksheetFunction.Substitute(Cell.Value, ".", ",")
Next

而这一个

Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, Cells(1, Columns.Count).End(xlToLeft).Column)).Select
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

但两者都给出了错误的结果。例如,对于124.419022,它给出124 419 022 而不是124.419022

任何人都可以帮我找到解决这个问题的方法吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

Private Sub Workbook_BeforeClose(Cancel As Boolean)
With Application
.DecimalSeparator = ","
.UseSystemSeparators = True
End With
End Sub

Private Sub Workbook_Open()
With Application
.DecimalSeparator = "."
.UseSystemSeparators = False
End With
End Sub