1) Mình thấy code của bạn chạy hơi chậm so với code trong file #1.
2) Mình thử với dòng này M3 : 38*83.564*89
sau khi nhấn Enter thì ra kêt quả 282.613,4
Mình muốn sau khi Enter thì cell đó sẽ là M3 : 38*83,564*89 = 282.613,448
Nghĩa là kết quả có
+) dấu phân cách hàng nghìn, hàng triệu là dấu chấm
+) dấu phân cách hàng thập phân là dấu phảy
+) Có 3 chữ số sau dấu phảy
Bạn thử kiểm tra xem
------------
Trong diễn giải:
1. Phải có ký tự ":". Sau ký tự ":" là biểu thức.
2. Chỉ dùng dấu chấm "." làm dấu thập phân
code của sheet
Mã:
Function FormatWithComma(ByVal number As Double) As String
Dim text As String, result As String
text = Format(2001 / 2, "#,##0.0")
result = Format(number, "#,##0.0##")
If Mid(text, 6, 1) = "," Then
FormatWithComma = Replace(result, Mid(text, 2, 1), ".")
Else
result = Replace(result, ".", "@")
result = Replace(result, Mid(text, 2, 1), ".")
FormatWithComma = Replace(result, "@", ",")
End If
End Function
Private Sub Worksheet_Change(ByVal Target As Range)
Dim expression As String
If Not Intersect(Target, Range("A1:A10000")) Is Nothing Then
If Target.Count = 1 Then
If Target.Value <> "" And InStr(Target, ":") > 0 Then
expression = Trim(Split(Target.Value, ":")(1))
Application.EnableEvents = False
On Error GoTo end_
Target.Value = Trim(Target.Value) & " = " & FormatWithComma(Evaluate(expression))
End If
End If
End If
end_:
Application.EnableEvents = True
End Sub