I liked the thought of adding a message box with the yes no option. So I tried to add one, but even when I select No it still insert new entry.
I also added Sheet protection
Code: Select all
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
' Appends data entry to dynamic validation range on right click
' The validation range must have nothing below
Dim inter As Range ' a cell with validation, maybe
Dim cell As Range
Dim r As Range ' validation range
Dim sVal As String ' list validation formula
Dim Answer As String
Dim MyNote As String
'If Target.Count > 1 Then Exit Sub '------------------------------------->
ActiveSheet.Unprotect Password:=""
'Place your text here
MyNote = "Do you wish to save"
'Display MessageBox
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Adding Comment to list")
If Answer = vbNo Then
'Code for No button Press
MsgBox "You pressed NO! Cancel Comment"
Else
'Code for Yes button Press
MsgBox "Comment has been added!"
End If
On Error Resume Next
Set inter = Intersect(Target, Cells.SpecialCells(xlCellTypeAllValidation))
If inter Is Nothing Then Exit Sub ' ------------------------------------>
For Each cell In inter
If cell.Validation.Type <> xlValidateList Then Exit Sub '------------->
sVal = cell.Validation.Formula1
If Left(sVal, 1) <> "=" Then Exit Sub ' ------------------------------->
Set r = ThisWorkbook.Names(Mid(sVal, 2)).RefersToRange
If r Is Nothing Then Exit Sub ' --------------------------------------->
If IsNumeric(Application.Match(cell.Text, r, 0)) Then Exit Sub '------>
Cancel = True
With r
.Parent.Cells(Me.Rows.Count, .Column).End(xlUp)(2).Value = cell.Text
.Resize(.Count + 1).Sort _
Key1:=r(1), Order1:=xlAscending, _
MatchCase:=False, Orientation:=xlTopToBottom, Header:=xlNo
End With
Next cell
Beep ' the sound of success
ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:=True, Password:=""
End Sub