Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Combine three procedures in VBA

Good afternoon,

I am trying to combine the three following VBA segments without any luck. Searching hasn’t done me much good. Would appreciate any assistance.

Sub UnProtectSheetWithPassword()

Sheets("Sheet2").Unprotect Password:="myPassword

End Sub"
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("O3").Address Then
        Range("B8:Q507").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("O2:O3")
    End If
End Sub
Sub ProtectSheetWithPassword()

Sheets("Sheet2").Protect Password:="myPassword"

End Sub

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Maybe this is what you want ?

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = Range("O3").Address Then
        Sheets("Sheet2").Unprotect Password:="myPassword"
        Range("B8:Q507").CurrentRegion.AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range("O2:O3")
        Sheets("Sheet2").Protect Password:="myPassword"
    End If
End Sub
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading