Consulting

Results 1 to 3 of 3

Thread: Solved: Entering Value in Combobox with Dynamic Range

  1. #1
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location

    Solved: Entering Value in Combobox with Dynamic Range

    Hello all,

    I use the following code to fill a Combobox with data stored somewhere else.
    It works fine but I like to be able to fill in a value that isn't in the list already.
    Do you guys have an idea?

    [vba]Private Sub UserForm_Initialize()
    Dim I As Range
    Dim ws As Worksheet

    Set ws = Worksheets("Data")
    For Each I In ws.Range("Data")
    Me.ComboBox1.AddItem I.Value
    Next I
    End Sub
    [/vba]
    [vba]
    Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex > -1 Then
    Exit Sub
    Else
    MsgBox ComboBox1 & " Not Found"
    End If
    End Sub[/vba]

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Perhaps this will do what you want
    [VBA]Private Sub ComboBox1_AfterUpdate()
    With ComboBox1
    If .ListIndex = -1 Then
    If .Text <> vbNullString Then
    .AddItem .Text
    End If
    End If
    End With
    End Sub[/VBA]

  3. #3
    VBAX Regular
    Joined
    May 2011
    Posts
    46
    Location
    Works fine, thanks Mike!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •