简体   繁体   中英

Protect a specific range on an excel sheet VBA

I have a filter program that I want to apply. But I want to apply it on protected range : columns A:H.

I tried using this

Sub Protect()
    ActiveSheet.Unprotect "lemotdepasse"
'Placez ici vos instructions
    ActiveSheet.Protect "lemotdepasse", True, True, True
End Sub

*But it applies to the whole sheet. I would like to apply it only on columns A:H.

Try this

Sub Protect()
    With ActiveSheet
        .Unprotect "lemotdepasse"
        .Range("A:H").AutoFilter
        .Protect "lemotdepasse", True, True, True
    End With
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM