Option Explicit
Sub CopyFirstCell()
Dim rngSource As Range, rngTarget As Range
Dim password As String
'假设你保护工作的密码为123456
password = "123456"
'取消保护工作表
ActiveSheet.Unprotect password
'如果未设置密码或者要求操作人员输入密码则将上句替换为:
'ActiveSheet.Unprotect
On Error Resume Next
Set rngSource = Range("B2:I8").SpecialCells(xlCellTypeConstants).Cells(1, 1)
If Err.Number > 0 Then
MsgBox "源区域未发现内容!"
Exit Sub
End If
On Error GoTo 0
Set rngTarget = Range("B10").Offset(rngSource.Row - 2, rngSource.Column - 2)
rngTarget = rngSource
rngSource.ClearContents
'重新保护工作表
ActiveSheet.Protect password
End Sub
其实我在你上个问题的评论中已经回答了哦.
你取消保护不就可以了吗,如果你不取消保护,是无法复制数据的,但你可以用代码取消保护,复制完再保护上取可
当然,你也可以保护工作表时,把需要的操作保留不被限制