我有一个包含 50 多个工作表的现有工作簿。我需要锁定每个现有工作表的单元格范围(b7:b51)。我尝试使用循环来执行此操作,并且我有一个循环代码,它确实遍历了所有工作表,我需要输入正确的代码来锁定单元格。
Sub WorksheetLoop()
Dim WS_Count As Integer
Dim I As Integer
' Set WS_Count equal to the number of worksheets in the active
' workbook.
WS_Count = ActiveWorkbook.Worksheets.Count
' Begin the loop.
For I = 2 To WS_Count
ActiveSheet.range("B1:B51").locked=true. --this is not correct.
MsgBox ActiveWorkbook.Worksheets(I).Name
Next I
End Sub
谢谢