Hi Jalal,
In the ThisWorkbook module, add the following code:
'=========>>
Option Explicit
'--------->>
Private Sub Workbook_Open()
Call ProtectIt
End Sub
'<<=========
In the code module of the Calc sheet, restore the original code:
'=========>>
Option Explicit
'--------->>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim strList As String
On Error Resume Next
Application.EnableEvents = False
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Not Intersect(Target, rngDV) Is Nothing Then
If Target.Validation.Type = 3 Then
strList = Target.Validation.Formula1
strList = Right(strList, Len(strList) - 1)
strDVList = strList
frmDVList.Show
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
'--------->>
' Developed by Contextures Inc.
' www.contextures.com
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim strSep As String
strSep = ", "
Application.EnableEvents = False
On Error Resume Next
If Target.Count > 1 Then GoTo exitHandler
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If newVal = "" Then
'do nothing
Else
If oldVal = "" Then
Target.Value = newVal
Else
Target.Value = oldVal & strSep & newVal
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
'<<=========
In your standard module, replace the existing declaration with:
'=========>>
Option Explicit
Global strDVList As String
Public Const sPassword As String = "ABC" '<<==== Change to suit
'--------->>
Public Sub ProtectIt()
Dim WB As Workbook
Dim SH As Worksheet
Set WB = ThisWorkbook
Set SH = WB.Sheets("Calc")
SH.Protect Password:=sPassword, _
UserinterfaceOnly:=True
End Sub
'--------->>
Public Sub UnprotectIt()
Dim WB As Workbook
Dim SH As Worksheet
Set WB = ThisWorkbook
Set SH = WB.Sheets("Calc")
SH.Unprotect Password:=sPassword
End Sub
'<<=========
In order to unprotect and re-protect the sheet for manual maintenance, execute the
UnprotectIt and ProtectIt macros.
Because of the use of the UserInterfaceOnly argument of the protect method, you can operate on the protected sheet
via code as if the sheet were unprotected. Because this setting is not persistent between Excel sessions, the initial protection is called in the Workbook_Open event.
I have uploaded the updated file Jalal20150324,xlsm at: http://1drv.ms/1dbCieY
===
Regards,
Norman