+ Reply to Thread
Results 1 to 10 of 10

Problem with populating ComboBox list

  1. #1
    Registered User
    Join Date
    07-12-2021
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Problem with populating ComboBox list

    Hello,

    I am having a problem populating a list using the following code:
    ------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub savedQuoteDetails_DropButtonClick()

    savedQuoteDetails.List = Sheets("Input_Sheet_List").ListObjects("Input_Sheet_List").ListColumns(1).DataBodyRange.Value

    End Sub
    -------------------------------------------------------------------------------------------------------------------------------------------
    The combo box = savedQuoteDetails
    The sheet = Input_Sheet_List
    The table = Input_Sheet_List

    I am trying to populate this list from the 1st column of the table.

    The code works perfect as long as there are at least 2 rows of data, however if I clear the table or only have 1 row of data in the table the code does not work. I get a "Run-time error '381': Could not set the List property. Invalid property array index." message.

    Can this issue be resolved?

    Thanks in advance,

    Greg

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,468

    Re: Problem with populating ComboBox list

    Hi Greg,

    It can indeed be resolved. One way would be to test how many rows of data are in the table and add them in one of two ways depending on the result.

    Please Login or Register  to view this content.
    BSB

  3. #3
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Problem with populating ComboBox list

    Hello. Try it with:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-12-2021
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: Problem with populating ComboBox list

    Thank you for your suggestion BadlySpelledBuoy, it is much appreciated. When I run the code I get a "Compile error: Expected Function or variable" message and it highlights the ".Additem ="

  5. #5
    Registered User
    Join Date
    07-12-2021
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: Problem with populating ComboBox list

    Thank you beyond Excel. I don't get any errors with your code, however I am unable to select anything from the combo box.

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Problem with populating ComboBox list

    Quote Originally Posted by GregMachar View Post
    ... however I am unable to select anything from the combo box.
    Mmm... that's "another movie", hehehe
    I don't know the source of this other problem, so you should upload a reduced model of your workbook to the forum to get a closer look at the problem you describe.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,581

    Re: Problem with populating ComboBox list

    GregMachar,

    Do you need it via DropButtonClick event?
    This is Userform Initialize event instead.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-12-2021
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: Problem with populating ComboBox list

    Brilliant jindon... I copied this code into my DropButtonClick event and it seems to be working beautifully. Thank you so much for your help!

  9. #9
    Registered User
    Join Date
    07-12-2021
    Location
    Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: Problem with populating ComboBox list

    jindons solution has fixed that event (A big thank you to jindon!) however I am now having the same issue with the events to make the combo box searchable.

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub savedQuoteDetails_Change()

    Dim i As Long

    If Not IsArrow Then
    With Me.savedQuoteDetails
    .List = Sheets("Input_Sheet_List").ListObjects("Input_Sheet_List").ListColumns(1).DataBodyRange.Value
    .ListRows = Application.WorksheetFunction.Min(20, .ListCount)
    .DropDown
    If Len(.Text) Then
    For i = .ListCount - 1 To 0 Step -1
    If InStr(1, .List(i), .Text, vbTextCompare) = 0 Then .RemoveItem i
    Next
    .DropDown
    End If
    End With
    End If

    End Sub

    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Private Sub savedQuoteDetails_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    IsArrow = (KeyCode = vbKeyUp) Or (KeyCode = vbKeyDown)
    If KeyCode = vbKeyReturn Then Me.savedQuoteDetails.List = Sheets("Input_Sheet_List").ListObjects("Input_Sheet_List").ListColumns(1).DataBodyRange.Value
    End Sub
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Can anyone see a way to fix this?

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,581

    Re: Problem with populating ComboBox list

    Better upload a workbook and explain what you are trying to do, rather than posting non workbokng codes.

    It will be totaly a guess work for us.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] ActiveX Combobox in worksheet when populating the list based on another Combobox get error
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-27-2020, 10:54 AM
  2. [SOLVED] Populating a ComboBox from two columns (as list not beside each other)?
    By LIL2606 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 04-07-2019, 03:24 PM
  3. Populating an ActiveX combobox from a dynamic list
    By Mel_GC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-23-2014, 11:10 AM
  4. Problem populating my combobox
    By psboyboy13 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-18-2012, 03:26 PM
  5. Combobox Populating via a list or directly typing
    By nighttrainrex in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-30-2011, 05:03 PM
  6. Populating the list in a combobox based off the value chosen in another combobox
    By Mervil in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2010, 11:50 AM
  7. ComboBox populating problem
    By Werner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-29-2005, 05:00 PM

Tags for this Thread

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