I need a macro to lock all worksheets and cells. ChatGPT gave me the following but it does not work.
I get the following error:
When I debug it highlights the following line in the macro:
Does anyone have any suggestions?
Quote:
Sub LockAllWorksheetsAndCells()
Dim ws As Worksheet
Dim cell As Range
' Loop through all worksheets in the workbook
For Each ws In ThisWorkbook.Sheets
' Protect the worksheet
ws.Protect
' Loop through all cells in the worksheet
For Each cell In ws.UsedRange
' Lock each cell
cell.Locked = True
Next cell
Next ws
End Sub
I get the following error:
Quote:
Unable to set the Locked property of the Range class
When I debug it highlights the following line in the macro:
Quote:
cell.Locked = True
Does anyone have any suggestions?