pham ha 94
Thành viên chính thức


- Tham gia
- 13/12/22
- Bài viết
- 86
- Được thích
- 6






Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lr&
lr = Cells(Rows.Count, "B").End(xlUp).Row
If Intersect(Target, Range("A2:A" & lr)) Is Nothing Or Target.Count > 1 Or UCase(Target) <> "X" Then Exit Sub
With Application
.EnableEvents = False
Range("A2:A" & lr).ClearContents
Target.Value = "X"
.EnableEvents = True
End With
End Sub






Private Sub Worksheet_Change(ByVal t As Range)
Static tm!: If tm > (Timer - 0.1) Then Exit Sub
Dim rg As Range, v
Set rg = Range("TickCells")
If Not CellSingle(t, rg) Then Exit Sub
v = t.Value: If v = Empty Then Exit Sub
tm = Timer
On Error Resume Next
Set rg = rg.SpecialCells(2): If Not rg Is Nothing And Err = 0 Then rg.ClearContents
t.Value = v:
End Sub
Function CellSingle(ByVal t As Range, Optional ByVal Target As Range) As Boolean
On Error Resume Next
CellSingle = t(1, 1).MergeArea.Address = t.Address
If CellSingle Then If Not Target Is Nothing Then CellSingle = (t.Column = Target.Column) And (t.Row >= Target.Row) And (t.Row < (Target.Row + Target.Rows.Count))
On Error GoTo 0
End Function


Minh copy toan bo code vao sheet1 thi thay bao loi tai dong 4: Set rg = t.Parent.Range("TickCells")Private Sub Worksheet_Change(ByVal t As Range) Static tm!: If tm > (Timer - 0.05) Then Exit Sub Dim rg As Range, v Set rg = t.Parent.Range("TickCells") If Not CellSingle(t, rg) Then Exit Sub v = t.value: If v = Empty Then Exit Sub Set rg = rg.SpecialCells(2): If Not rg Is Nothing Then rg.ClearContents t.value = v: tm = Timer End Sub Function CellSingle(ByVal t As Range, Optional ByVal Target As Range) As Boolean On Error Resume Next CellSingle = t(1, 1).MergeArea.Address = t.Address If CellSingle Then If Not Target Is Nothing Then CellSingle = (t.Column = Target.Column) And (t.Row >= Target.Row) And (t.Row < (Target.Row + Target.Rows.Count)) On Error GoTo 0 End Function
View attachment 286934
minh tao roi nhung van khong chay b a
Set rg = t.Parent.Range("TickCells")Ban xem giup minh duoc khong, bao loi suot y


Bạn chép lại mã, thử lại xem saoChạy một xíu là sẽ đơ và mất code đóng file excel luôn ý


b có thể xem giúp mình file m đính kèm bên trên được không, mình thử code nhiều lần vẫn lỗi.Bạn chép lại mã, thử lại xem sao
Bạn kiểm thử lại xem saob có thể xem giúp mình file m đính kèm bên trên được không, mình thử code nhiều lần vẫn lỗi.
Cảm ơn bạn nhiều




Mình Sửa lại code này một chút ở dòng Target.Value = "X" thành Cells(Target.Row, "A").Value = "X"Dùng sự kiện worksheet_Change nhé
Click chuột phải và tên sheet, View Code, rồi dán code phía dưới vào:
PHP:Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim lr& lr = Cells(Rows.Count, "B").End(xlUp).Row If Intersect(Target, Range("A2:A" & lr)) Is Nothing Or Target.Count > 1 Or UCase(Target) <> "X" Then Exit Sub With Application .EnableEvents = False Range("A2:A" & lr).ClearContents Target.Value = "X" .EnableEvents = True End With End Sub