Bổ sung code Highlight khi tắt Checkbox sẽ cho copy & Paste!
Em chào thầy cô & Anh chị!
Em có code Highlight có sử dụng checkbox để ON/OFF Highlight
Vui lòng sửa giúp em code với yêu cầu sau:
Bây giờ em muốn khi khi OFF Highlight (tắt CheckBox) thì có thể Copy & Paste trong sheet đó được!
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.ScreenUpdating = False
If Range("a1") = True Then
Rows.Interior.ColorIndex = xlColorIndexNone
Target.EntireColumn.Interior.ColorIndex = 36
Target.EntireRow.Interior.ColorIndex = 36
Else
Rows.Interior.ColorIndex = xlColorIndexNone
End If
Application.ScreenUpdating = True
End Sub
Em cảm ơn!
Chứ hiện giờ không Copy/Paste được à?
Copy thì được, nhưng Paste ở tại Sheet hiện hành thì không được, Sheet khác thì được
———
P/S: không biết vì sao Thầy hỏi câu trên? Dĩ nhiên em biết sử dụng sự kiện ở Bài #1 thì kg thể Paste!
———
P/S: không biết vì sao Thầy hỏi câu trên? Dĩ nhiên em biết sử dụng sự kiện ở Bài #1 thì kg thể Paste!
Tôi hỏi vậy là vì tôi có thấy gì bất thường đâu. File của bạn tôi copy/paste thoải mái ở cả sheet hiện hành và sheet khác
Vậy mà nó không cho Paste ở Sheet hành!!!
Thì làm vầy đi:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.CutCopyMode = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Application.CutCopyMode = False Then
Application.ScreenUpdating = False
If Range("a1") = True Then
Rows.Interior.ColorIndex = xlColorIndexNone
Target.EntireColumn.Interior.ColorIndex = 36
Target.EntireRow.Interior.ColorIndex = 36
Else
Rows.Interior.ColorIndex = xlColorIndexNone
End If
Application.ScreenUpdating = True
End If
End Sub
Theo tôi đã dùng checkbox rồi thì nên làm như vầy đi, cần gì đến cái ô A1 nữa chứ!
Option Explicit
Private Sub CheckBox1_Change()
If CheckBox1 = False Then
Cells.Interior.ColorIndex = xlColorIndexNone
Else
Application.CutCopyMode = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If CheckBox1 = False Then Exit Sub
Application.CutCopyMode = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If CheckBox1 = False Then Exit Sub
If Application.CutCopyMode = False Then
Application.EnableEvents = False
Cells.Interior.ColorIndex = xlColorIndexNone
Target.EntireColumn.Interior.ColorIndex = 36
Target.EntireRow.Interior.ColorIndex = 36
Application.EnableEvents = True
End If
End Sub
Bạn có thể copy với bất cứ lúc nào bạn muốn! Lưu ý, chỉ paste được có 1 lần thôi, khi nó đang check, còn không thì Vô Tư!
Bạn bỏ cái LinkCell A1 đi.
Không biết các bạn khác test thế nào, riêng trên máy tôi thì paste ở đâu cũng được cả (kể cả khi CheckBox = True hoặc False)
Học Nhân sự Tổng hợp – Trở thành chiến binh nhân sự vững nghiệp vụ
Con người là một trong những yếu tố quan trọng của công ty, là tài sản quý giá của doanh nghiệp. Chính vì thế,...
Xem khóa học