Hi All, Im using the following code to lock cells Ive obviously doing something wrong as I'm trying to make this work on all the worksheets. Can anyone help or point me in the right direction
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If InStr(LCase(Sheets(i).Name), "dvsa") Then
On Error Resume Next
'Resume to next line if any error occurs
Dim Cell As Range
With ActiveSheet
'first of all unprotect the entire
'sheet and unlock all cells
.Unprotect Password:="snails"
.Cells.Locked = False
'Now search for non blank cells
'and lock them and unlock blank cells
For Each Cell In ActiveSheet.UsedRange
If Cell.Value = "" Then
Cell.Locked = False
Else
Cell.Locked = True
End If
Next Cell
.Protect Password:=""
'Protect with blank password, you can change it
End With
Exit Sub
End If
End Sub