我有一些Excel宏,人们在执行之前手动将其粘贴到数据中。
为避免宏运行中的错误,我想禁用某些列粘贴其中的数据。
我试过
Private Sub Worksheet_Change(ByVal Target As Range)
Target.Column = 7
Target.Column = 8
Target.Column = 12
End Sub
有人可以指导我怎么可能吗?
答案 0 :(得分:3)
尝试下面的代码,将其添加到您要阻止用户粘贴到某些列的工作表中。
Private Sub Worksheet_Change(ByVal Target As Range)
' Restrict the user from deleting or Pasting to certain columns
Select Case Target.Column
Case 7, 8, 12
With Application
.EnableEvents = False
.Undo
MsgBox "Pasting to columns 'F' , 'G' or 'L' is not allowed", vbCritical
.EnableEvents = True
End With
Case Else
' do nothing / or something else
End Select
End Sub