Home > Blockchain >  Combine three procedures in VBA
Combine three procedures in VBA

Time:05-04

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

CodePudding user response:

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
  • Related