- Tham gia
- 22/7/14
- Bài viết
- 355
- Được thích
- 31
Mình có 1 bảng tính Excel, mình muốn trong vùng A1:A100 không cho Cut , các thao tác còn lại, copy, paste, nhập liệu........bình thường



Mình có 1 bảng tính Excel, mình muốn trong vùng A1:A100 không cho Cut , các thao tác còn lại, copy, paste, nhập liệu........bình thường
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
If Not Intersect(ActiveCell, Range("A1:A100")) Is Nothing Then
With Application
.OnKey "^x", "CutDisabled"
.CellDragAndDrop = False
If Application.CutCopyMode = xlCut then
.CutCopyMode = False
End If
End With
Else
Application.OnKey "^x"
End If
End Sub
Sub CutDisabled()
'Inform user that the functions have been disabled
MsgBox "Sorry! Cutting has been disabled for this range!"
End Sub
code của bạn vẫn cut paste bình thường trong vùng cấm màBạn làm như sau với trường hợp dùng Ctrl + X để cut
1. Mở VBA Editor lên và trong ThisWorkBook nhập code sau:
PHP:Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) If Not Intersect(ActiveCell, Range("A1:A100")) Is Nothing Then With Application .OnKey "^x", "CutDisabled" .CellDragAndDrop = False If Application.CutCopyMode = xlCut then .CutCopyMode = False End If End With Else Application.OnKey "^x" End If End Sub
2. Thêm 1 module vào và nhập code sau vào module đó:
PHP:Sub CutDisabled() 'Inform user that the functions have been disabled MsgBox "Sorry! Cutting has been disabled for this range!" End Sub
Xem file để biết thêm chi tiết và ghé channel youtube của mình
Bạn làm như sau với trường hợp dùng Ctrl + X để cut
1. Mở VBA Editor lên và trong ThisWorkBook nhập code sau:
PHP:Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range) If Not Intersect(ActiveCell, Range("A1:A100")) Is Nothing Then With Application .OnKey "^x", "CutDisabled" .CellDragAndDrop = False If Application.CutCopyMode = xlCut then .CutCopyMode = False End If End With Else Application.OnKey "^x" End If End Sub
2. Thêm 1 module vào và nhập code sau vào module đó:
PHP:Sub CutDisabled() 'Inform user that the functions have been disabled MsgBox "Sorry! Cutting has been disabled for this range!" End Sub
Xem file để biết thêm chi tiết và ghé channel youtube của mình



code của bạn vẫn cut paste bình thường trong vùng cấm mà



code của bạn vẫn cut paste bình thường trong vùng cấm mà
cảm ơn bạn, code của bạn đúng theo ý của mình rồi, nhưng mình muốn 1 vùng A1:A100 của sheets("data") thôi thì thay đổi chổ nào
If Not Intersect(ActiveCell, Sheets("data").Range("A1:A100")) Is Nothing Then
Mình thay đổi như trên được bạn ơi giúp mình với