Hello,
In my code below, the sheet protection is re-activated automatically after the line ".ClearContents". To Avoid this situation, I must unprotect the sheet again between the lines ".ClearContents" and ".Locked = True"
Any idea why this is happening and how I can avoid unprotecting my sheet again the the middle of my code ?
Another less important question, My screenUpdating = False doesn`t seems to work, any suggestion ?
I dont know if it has any influence, but the macro is activated on a change of a specific cell.
In my code below, the sheet protection is re-activated automatically after the line ".ClearContents". To Avoid this situation, I must unprotect the sheet again between the lines ".ClearContents" and ".Locked = True"
Any idea why this is happening and how I can avoid unprotecting my sheet again the the middle of my code ?
Another less important question, My screenUpdating = False doesn`t seems to work, any suggestion ?
I dont know if it has any influence, but the macro is activated on a change of a specific cell.
VBA Code:
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
With Worksheets("Sheet1")
.Unprotect Password:="2020"
.DisplayPageBreaks = False
End With
Dim FileType As String
Dim ws1 As Worksheet
Dim rngA As Range
Dim rngB As Range
Set ws1 = Worksheets("Sheet1")
With ws1
Set rngA = .Range("M30:M35, K42:M43, K44")
Set rngB = .Range("I37:K39, L47:L48")
End with
FileType = ws1.Range("E10").Value2
If FileType = "AAA" Then
With rngB
.Interior.Pattern = (14)
.ClearContents
.Locked = True
End With
With rngA
.Interior.Pattern = (-4142)
.Locked = False
End with
End If
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
With Worksheets("Sheet1")
.DisplayPageBreaks = True
.Protect Password:="2020"
End With