- Tham gia
- 23/3/16
- Bài viết
- 705
- Được thích
- 52
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D2:D65000"))) Is Nothing) Then
If Target.Offset(, -1).Value = "" Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End If
End Sub
Bạn sử dụng đoạn code này thử đúng ý chưa.
[Mã:Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D2:D65000"))) Is Nothing) Then If Target.Offset(, -1).Value = "" Then Application.EnableEvents = False Application.Undo Application.EnableEvents = True End If End If End Sub
Em vô cùng hoàn toàn đồng ý với Code của anh
Cho em hỏi 3 đoạn này có ý nghỉa gì
If Target.Cells.Count > 1 Then Exit Sub
If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D265000"))) Is Nothing) Then
If Target.Offset(, -1).Value = "" Then
Anh có thể làm ngằn gọn thành 1 cái được không
Giải thích từng đoạn nhé.Bạn sử dụng đoạn code này thử đúng ý chưa.
[Mã:Private Sub Worksheet_Change(ByVal Target As Range) If Target.Cells.Count > 1 Then Exit Sub If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D2:D65000"))) Is Nothing) Then If Target.Offset(, -1).Value = "" Then Application.EnableEvents = False Application.Undo Application.EnableEvents = True End If End If End Sub
Em vô cùng hoàn toàn đồng ý với Code của anh
Cho em hỏi 3 đoạn này có ý nghỉa gì
If Target.Cells.Count > 1 Then Exit Sub
If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D265000"))) Is Nothing) Then
If Target.Offset(, -1).Value = "" Then
Anh có thể làm ngằn gọn thành 1 cái được không
Muốn gom thành một cái If hay không thì tùy bạn, nhưng tôi muốn viết cho dễ hiểu thôi, bạn muốn gom thì thêm điều kiện And nửa thôi.Mã:If Target.Cells.Count > 1 Then Exit Sub ' [COLOR=#ff0000][B]Nếu thay đổi nhiều hơn 1 ô thì thoát khỏi sub[/B][/COLOR] If Not (Intersect(Target, Union(Range("C2:C65000"), Range("D2:D65000"))) Is Nothing) Then '[COLOR=#ff0000][B]Nếu ô vừa thay đổi giá trị nằm trong vùng từ C2:D65000 thì sét tiếp [/B][/COLOR]' [B][COLOR=#ff0000]Có thể sửa dòng trên là [/COLOR][COLOR=#0000ff]If Not (Intersect(Target, [C2:D65000]) Is Nothing) Then[/COLOR][/B] If Target.Offset(, -1).Value = "" Then '[COLOR=#ff0000][B] Nếu ô trước ô đang sửa không có gí trị thì[/B][/COLOR]