+ Reply to Thread
Results 1 to 11 of 11

Populate controls based on selected multicolumn Listbox item

  1. #1
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Populate controls based on selected multicolumn Listbox item

    Hello. I've read many posts regarding populating userform controls from listboxes and the below code is about as generic as you can get. The example below is for a listbox that is rowsourced in the vb properties window. I've tried other code that uses vb to source the data. The multicolumn listbox populates correctly on initialization. However, when I run the click event on my form, it has a run-time errror (could not get the list property. Invalid argument) on line #3. The combo and textbox names are correct as is the listbox name.

    Like I've said, I've tried a variety of other methods found in every forum I can find, and found that the syntax seems to be correct, but I continue more often than not to get the same run-time error. I can only assume this is a problem created by how the listbox was sourced when initialized, but that to me doesn't seem like it would matter. I have been beating my head on this for days and cannot seem to figure this out. It seems so simple by looking at other posts! If there is a caveat with initialization, I can post the code used for that procedure if needed.
    Please Login or Register  to view this content.
    Last edited by terriertrip; 12-05-2016 at 07:23 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Populate controls based on selected multicolumn Listbox item

    That code is populating the textboxes from columns 2, 3 and 4 of the listbox, what colums does your code use and how many columns does your listbox have?
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    The columns are using D:F (there are data in A:C) and my listbox has 3 columns. It was my understanding that column indexes start A=0, B=1, etc. Is that incorrect?

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Populate controls based on selected multicolumn Listbox item

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

  5. #5
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    Thank you for your assistance Norie. Attached is a sample wb. I stripped it down and excluded several other subs and lines of code that didn't have to necessarily do with this particular element.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    Hello Norie. Was the attached file not sufficient or too unclear?

    I have several forms containing listboxes that need to reference a LookupList sheet that has many discreet attributes (i.e. column data). I'm trying to understand what the correct syntax would be to reference a set of specific columns (with the ability to dynamically add/edit/save data in the rows to those columns). The same code, in my mind, could then be applied to the multiple listbox forms that populate and allow user to add/edit/save to those listboxes.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Populate controls based on selected multicolumn Listbox item

    Sorry for not getting back sooner - think I missed your last post.

    Anyway, the listbox on your userform has 3 columns, in this code you are trying to refer to columns 4, 5 and 6 of the listbox.
    Please Login or Register  to view this content.
    Try changing it to this.
    Please Login or Register  to view this content.
    That will fix that error but unfortunately brings up another error here.
    Please Login or Register  to view this content.
    In this code LastCol is never given a value so Cells(2,LastCol) will fail.

    What is it you are trying to do here?

  8. #8
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    No problem - appreciate your response. Wow. I see my misunderstanding now. I thought the columns 3,4,5 we're referencing the worksheet columns (D,E,F), not the listbox. Thank you very much for making that clear.

    The last line of code I have decided to omit from this particular form since I thought it more simple to let the listbox do the selecting for user to edit (therefore cbTextBox1 becomes txtTextBox1). I see the problem there with LastCol.

    However, since I would like to use this in other aspects, what I am trying to do with this dropdown combo selection is something akin to vlookup? If user selects variable from dropdown combo, any associated data attributes in corresponding row would populate to textboxes to allow user to edit. Since the range is discreet, LastCol would not be needed. In this case would the code look like this?
    Please Login or Register  to view this content.
    Last edited by terriertrip; 11-29-2016 at 05:04 PM.

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Populate controls based on selected multicolumn Listbox item

    So you want to find which row the value selected in the combobox comes from and then use that to populate the textboxes?

    Which column would you want to look for the value from the combobox?

  10. #10
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    Yes.

    The combobox value would reside in D.

  11. #11
    Forum Contributor
    Join Date
    02-25-2013
    Location
    Colorado, US
    MS-Off Ver
    Microsoft 365 Apps
    Posts
    518

    Re: Populate controls based on selected multicolumn Listbox item

    Hi Norie,

    It's been awhile I know. I don't know if you received my post back in November but I am finally getting back to my project am trying to pick back up where I left off. I am using the commercial services. Are you available for consultation on this?

+ 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. Listbox add item multicolumn
    By Code Flunkie in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-23-2016, 12:46 PM
  2. I want to populate a listbox with a combobox selected item.
    By Bailers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2014, 06:42 AM
  3. Copy Selected items from multicolumn, multiselect listbox to another listbox
    By Willigb in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-19-2013, 11:27 AM
  4. VBA - Populate Listbox based on value selected in another ListBox (On Userform)
    By raaboo in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-12-2012, 11:18 AM
  5. Populate userform listbox based on value selected in another listbox
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-07-2012, 05:16 PM
  6. Populate ListBox Based On Item Chosen In Another ListBox
    By davemojo82 in forum Excel General
    Replies: 1
    Last Post: 08-04-2009, 08:39 AM
  7. [SOLVED] populate multicolumn listbox?
    By Alen32 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-22-2005, 06:06 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