The following is used with a dynamic validation list that includes "(new entry)" as one of the selections. When (new entry) is selected, a pop-up form appears, asking for the new entry.
I copied this from web source. The quotation marks did not copy correctly so I replaced them. After replacing them, it ran correctly 1 time -- but I can't get it to fire at all.
--------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim vResp As Variant
Dim sTestValid As String
'Make sure the cell has validation
On Error Resume Next
sTestValid = Target.Validation.Formula1
On Error GoTo 0
'If the validation refers to our list and the user
'selected New entry
If sTestValid = "=ValList" Then
If Target.Value = "(new entry)" Then
'Get the new value from the user
vResp = InputBox("Enter new item", "New Entry")
'If the user didn’t click cancel
If Len(vResp) > 0 Then
'add the new entry to just below ValList
With Me.Range("ValList")
.Cells(.Cells.Count + 1).Value = vResp
End With
'Set the cell to the new entry
Target.Value = vResp
Else
'If the user cancelled, clear the cell
Target.ClearContents
End If
End If
End If
Application.EnableEvents = True
End Sub
swtrader
-- If you don't know where you're going, you'll always know when you're not there.
I copied this from web source. The quotation marks did not copy correctly so I replaced them. After replacing them, it ran correctly 1 time -- but I can't get it to fire at all.
--------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Dim vResp As Variant
Dim sTestValid As String
'Make sure the cell has validation
On Error Resume Next
sTestValid = Target.Validation.Formula1
On Error GoTo 0
'If the validation refers to our list and the user
'selected New entry
If sTestValid = "=ValList" Then
If Target.Value = "(new entry)" Then
'Get the new value from the user
vResp = InputBox("Enter new item", "New Entry")
'If the user didn’t click cancel
If Len(vResp) > 0 Then
'add the new entry to just below ValList
With Me.Range("ValList")
.Cells(.Cells.Count + 1).Value = vResp
End With
'Set the cell to the new entry
Target.Value = vResp
Else
'If the user cancelled, clear the cell
Target.ClearContents
End If
End If
End If
Application.EnableEvents = True
End Sub
swtrader
-- If you don't know where you're going, you'll always know when you're not there.