+ Reply to Thread
Results 1 to 9 of 9

Populating selected range to listbox

  1. #1
    Registered User
    Join Date
    06-28-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2010
    Posts
    40

    Populating selected range to listbox

    Hi,

    I tried to populate selected range from worksheet to listbox.
    But notice that the whole thing gone wrong....

    Private Sub CommandButton1_Click()
    ListBox1.Value = Worksheets("Sheet1").Range("C:D;H:J;L;U:X;AI;AL:AM")
    End Sub

    I would like to have only the red range to be in the list box.


    can some one help me with this?

    really appreciate your help.

    regards
    VJ
    Attached Files Attached Files

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,647

    Re: Populating selected range to listbox

    I think you don't need a CommandButton click event to populate the ListBox.
    Why not populate the ListBox with UserForm initialize event?

    Place the below code into the UserForm Module.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    06-28-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2010
    Posts
    40

    Re: Populating selected range to listbox

    Thank you very much sir.... that's very nice.

    Just wondering why I only can see 6 items on the list box ? I have set 12 items.


    regards
    VJ

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,647

    Re: Populating selected range to listbox

    I didn't scroll to the right on the sheet and missed those columns.
    Replace the existing code with the following one.
    The red colored numbers in the code are the column indexes which are to be populated in the ListBox.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    06-28-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2010
    Posts
    40

    Re: Populating selected range to listbox

    Excel.gif

    done sir ... but cant see all when I play.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,647

    Re: Populating selected range to listbox

    To view those columns in the ListBox, you will need to set the ColumnCount property to 13.
    To do so, open the UserForm in design mode, select the ListBox and press F4 to open properties and locate ColumnCount and change it to 13. The existing ColumnCount is set to 6 so you can only view 6 columns in the Listbox.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,647

    Re: Populating selected range to listbox

    Here is the file for your reference.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-28-2015
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    2010
    Posts
    40

    Re: Populating selected range to listbox

    wonderful sir.... thanks you very much.
    how you did it?

    regards
    VJ

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,647

    Re: Populating selected range to listbox

    You're welcome VJ!
    As I told you that you were required to set the ColumnCount property for the ListBox to view all the columns.

    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

    You may also say thanks to those who have put their time and efforts to help you in this forum by clicking the Add Reputation link under their posts, another way to say thanks.

+ 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. Populating Listbox based on Date Range
    By McGuire1986 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2015, 09:47 AM
  2. Populating Userform Listbox with Dynamic Range
    By VBAerthang in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2013, 05:13 AM
  3. [SOLVED] Populating an array with selected ListBox items
    By wz4np1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2012, 07:52 AM
  4. [SOLVED] Populating a Worksheet with values selected from a Dynamic Listbox
    By hornbyOO in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-09-2012, 04:35 PM
  5. Populating a Range of Cells from a ListBox Selection
    By cmaitlen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2012, 07:06 PM
  6. listbox populating on userform with named range
    By kmsoni in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2011, 01:37 PM
  7. Populating a listbox from range xl2003
    By Ramthebuffs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-03-2005, 10:38 AM

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