+ Reply to Thread
Results 1 to 2 of 2

Selecting value in 2D ComboBox by hidden column

  1. #1
    Registered User
    Join Date
    05-24-2013
    Location
    Zürich
    MS-Off Ver
    Excel 2010
    Posts
    3

    Selecting value in 2D ComboBox by hidden column

    Dear VBA experts,

    I have a 2D combobox where in the shown column(0) the names of the database imports are listed and in the hidden column(1) the corresponding ID's of the DB imports.
    After I add the 2D list to the combobox I want to set the combobox value and thus by ID (column(1)), but I do not know how.

    I have tried the following:
    cboComboBox.Columns(1).Value = strID 'causes error

    A solution would be to get the .listindex of the combobox when the Columns(1).Value = strID

    Thank you for any help!

    Luka

  2. #2
    Registered User
    Join Date
    05-24-2013
    Location
    Zürich
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Selecting value in 2D ComboBox by hidden column

    I have found a way to loop through all the values of the combobox in the column(1) and check if the value equals the strID to get the ListIndex of the desired value:

    Dim intIndex As Integer
    Dim strID As String

    strID = "desired ID"

    For i = 0 To .cboCombobox.ListCount - 1
    If .cboCombobox.List(i, 1) = strID Then intIndex = i
    Next

    However, I do not realy like to do it this way, the looping might take significant time if database has many imports. Someone hopefully knows a better solution.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1