Hi Minitman,
You can use the RowSource property of the ComboBox to specify the source
range for the dropdown. If your named range is Jake, you would use =Jake if
setting it at design time (via the properties window). As long as the
MatchRequired property is False, the user will be able to enter a value that
doesn't match the current list.
Here's some quick and dirty code that will add an item to the named range
and the ComboBox:
Private Sub CBX1_AfterUpdate()
Dim l As Long
Dim bFound
Dim rng As Range
With CBX1
For l = 0 To .ListCount - 1
If StrComp(.Value, .List(l), _
vbTextCompare) = 0 Then
bFound = True
Exit For
End If
Next l
End With
If Not bFound Then
'/ add value to named range
With Range("Jake")
Set rng = .Resize(.Rows.Count + 1, _
.Columns.Count)
rng.Cells(.Rows.Count + 1, _
.Columns.Count).Value = CBX1.Value
End With
Names("Jake").RefersTo = "=" & rng.Address
CBX1.RowSource = "=Jake"
End If
End Sub
Seems to work, but you'll want to test it thoroughly and add some error
handling. This code should only add an item if it doesn't match an existing
list item.
--
Regards,
Jake Marx
MS MVP - Excel
www.longhead.com
[please keep replies in the newsgroup - email address unmonitored]
Minitman wrote:
Greetings,
I have a ComboBox (CBX1) on a UserForm (UF1) that needs to be loaded
from a named range (CustNames) on my spreadsheet.
I have CBX1, but I am not sure of the best way to load it. One
consideration is that sometimes there will not be a match in the
"CustNames" list for the name I need to enter, so I will need to enter
the name manually, directly into the ComboBox and if possible, have
VBA add that name into the "CustNames" list.
Is this possible? Any help would be appreciated.
TIA
-Minitman