Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo EH
Application.EnableEvents = False
Dim Cell As Range, TargetRange As Range
' Thiet lap vung nhap so can xu ly tu dong decimal
Set TargetRange = Me.Range("A2:A10")
If Not Intersect(Target, TargetRange) Is Nothing Then
For Each Cell In Target
' Bo qua su kien khi xoa nguyen cot --> se chay vong lap het 1.048.576 dong
If Target.Cells.Count > 1 Then
Application.EnableEvents = True
Exit Sub
End If
' Nhap 4 chu so => >10
If IsNumeric(Cell.Value) And Len(Cell.Value) > 3 Then
MsgBox "So lon hon thang diem 10."
Cell.Value = ""
Application.EnableEvents = True
Exit Sub
End If
If IsNumeric(Cell.Value) And Cell.Value <> 10 Then
Select Case Len(Cell.Value)
Case 2
Cell.Value = Cell.Value / 10
Case 3
Cell.Value = Cell.Value / 100
End Select
ElseIf Not IsNumeric(Cell.Value) Then 'Nhap chu
Cell.Value = ""
End If
Next Cell
End If
EH_Exit:
Application.EnableEvents = True
Exit Sub
EH:
MsgBox "An error occurred: " & Err.Description
Resume EH_Exit
End Sub