我想寫一個宏,在所有工作表中鎖定某些單元格 - 從A12到R的最後一行。是的,我得到使用查找:方法'範圍'的對象'_Worksheet'失敗「
錯誤1004:?在行
LastRow = wSheet.Cells.Find(What:="*", After:=[A1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row)
「方法 '範圍' 對象中」_Worksheet失敗「
誰能幫我謝謝!因爲它目前假定它找到至少一個非空單元時它設置LastRow
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
這個心不是你如何保護細胞。請看[這個答案](http://stackoverflow.com/questions/16684297/hiding-formulas-in-formula-bar/16686868#16686868) – 2013-07-03 11:28:23
刪除'After:= [A1],'part或qualify the [ A1]與wsheet – JosieP