I have the following code that "beforesave" searches the document and locks the cells that has data, and leaves empty cells unlocked. When save is clicked the userform shows. The useform is triggered by "worksheet selection change" cells B21 and B23 show userform2 and cell B37 userform1. How do I stop the userform from showing when the save button is clicked. I greatly appreciate the help and lesson. I can post the code for the userform if needed as well.
Code
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)Dim rng1 As Range
Dim rng2 As Range
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayAlerts = False
If ActiveSheet.Name = "Dept1" Then 'change name of sheet as needed
'Resume to next line if any error occurs
On Error Resume Next
Dim cell As Range
With ActiveSheet
.Unprotect Password:="open"
For Each cell In ActiveSheet.UsedRange
Set rng1 = Intersect(Cells.SpecialCells(xlFormulas), Cells.SpecialCells(xlBlanks))
Set rng2 = Intersect(Cells.SpecialCells(xlConstants), Cells.SpecialCells(xlBlanks))
ActiveSheet.UsedRange.Locked = False
If Not rng1 Is Nothing Then rng1.Locked = True
If Not rng2 Is Nothing Then rng2.Locked = True
Next cell
.Protect Password:="open"
End With
Application.Calculation = xlCalculationAutomatic
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
End Sub
Display More