我想写一个宏,在所有工作表中锁定某些单元格——从 A12 到 R 的最后一行。事情是,我得到了
错误 1004:“对象‘_Worksheet’的方法‘范围’失败”
排队
LastRow = wSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
.
谁能帮帮我?谢谢!
Option Explicit
Sub ProtectAll()
Dim wSheet As Worksheet
Dim Pwd As String
Dim LastRow As Integer
Pwd = InputBox("Enter your password to protect all worksheets", "Password Input")
For Each wSheet In Worksheets
LastRow = wSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
wSheet.Range(Cells(12, 1), Cells(LastRow, 18)).Select
wSheet.Protect Password:=Pwd, AllowFiltering:=True
Next wSheet
End Sub