|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If CDec(Target.Rows.Count) * Target.Columns.Count > 1 Then Exit Sub
Dim s As String, mark, i, j, t
s = Target.Value
If Len(s) = 0 Then Exit Sub
Application.EnableEvents = False
On Error GoTo errmsg
mark = "0.123456789,"
For i = Len(s) To 1 Step -1
If Mid(s, i, 1) = "Ԫ" Then
For j = i - 1 To 1 Step -1
If InStr(mark, Mid(s, j, 1)) = 0 Then
t = Mid(s, j + 1, i - j - 1)
s = Replace(s, t, Format(Replace(t, ",", vbNullString), "#,##0.00"))
i = j: Exit For
End If
Next
End If
Next
Target.Value = s
Application.EnableEvents = True
Exit Sub
errmsg:
Debug.Print "error"
Application.EnableEvents = True
End Sub |
|