Sub LockSpecificColumnsAndProtectSheet()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("WL")
' Define your password
Dim strPassword As String
Dim wbPassword As String
strPassword = "Oman@2024" ' Password for sheet protection
wbPassword = "OmanWb2024" ' Password for workbook protection
' Unprotect the sheet with the password if it's already protected
ws.Unprotect Password:=strPassword
' Unlock all cells on the sheet
ws.Cells.Locked = False
' Lock entire columns A, B, and H
ws.Columns("A").Locked = True
ws.Columns("B").Locked = True
ws.Columns("H").Locked = True
' Make sure that AutoFilters are enabled before protecting the sheet
If ws.AutoFilterMode = False Then
ws.Range("A1").AutoFilter
End If
' Protect the sheet with a password to enforce the locking
' Enable AllowFiltering to keep the drop-down filter option available
ws.Protect Password:=strPassword, DrawingObjects:=True, Contents:=True,
Scenarios:=True, AllowFiltering:=True
' Protect workbook to prevent hiding/unhiding sheets, renaming sheets,
moving/copying sheets, and changing tab colors
ThisWorkbook.Protect Password:=wbPassword, Structure:=True, Windows:=False
End Sub