VBA Code For the Day (Worksheet Protection)

Sub SetProtection() On Error GoTo errorHandler Dim myDoc As Worksheet Dim cel As Range Set myDoc = ActiveSheet myDoc.Unprotect For Each cel In myDoc.UsedRange If Not cel.HasFormula And _ Not TypeName(cel.Value) = "Date" And _ Application.IsNumber(cel) Then cel.Locked = False cel.Font.ColorIndex = 5 Else cel.Locked = True cel.Font.ColorIndex = xlColorIndexAutomatic End If Next myDoc.Protect Exit Sub errorHandler: MsgBox "Error" End Sub

Featured Posts