Bổ sung code Highlight khi tắt Checkbox sẽ cho copy & Paste! (1 người xem)

Người dùng đang xem chủ đề này

Hong.Van

Busy
Tham gia
7/5/12
Bài viết
2,328
Được thích
1,765
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!
PHP:
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!
 

File đính kèm

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!
PHP:
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 à?
 
Upvote 0
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!

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
 
Upvote 0
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!
PHP:
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!

Thì làm vầy đi:

PHP:
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
 
Upvote 0
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ứ!

PHP:
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.
 

File đính kèm

Lần chỉnh sửa cuối:
Upvote 0
Xác nhận: máy tôi paste đâu cũng được, dù check hay không.
 
Upvote 0
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)

Riêng WinXP với Excel 2003 thì không thực hiện được! Chắc Win7 hoặc Excel 2007-2010 đã cải tiến vấn đề này chăng?
 
Upvote 0
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ứ!

PHP:
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
.
Cho em hỏi nếu như em muốn sử dụng code trên để dùng cho nhiều sheet ( mỗi sheet không cần phải 1 code như vậy).
Chỉ dùng 1 code cho tât cả các sheet. Trên mỗi sheet sẽ có 1 checkbox, nếu checkbox ở sheet nào thì sẽ gọi code lên. và ngược lại
 
Upvote 0

Bài viết mới nhất

Back
Top Bottom