+ Reply to Thread
Results 1 to 7 of 7

Add unique Items to ListBox Dynamically

Hybrid View

AmirSoft Add unique Items to ListBox... 07-31-2015, 02:31 PM
jindon Re: Add unique Items to... 07-31-2015, 02:52 PM
AmirSoft Re: Add unique Items to... 08-01-2015, 12:02 AM
jindon Re: Add unique Items to... 08-01-2015, 12:31 AM
AmirSoft Re: Add unique Items to... 08-01-2015, 07:56 AM
jindon Re: Add unique Items to... 08-01-2015, 08:22 AM
AmirSoft Re: Add unique Items to... 08-02-2015, 01:25 AM
  1. #1
    Forum Contributor
    Join Date
    09-18-2014
    Location
    Pakistan
    MS-Off Ver
    2013, 2016
    Posts
    283

    Add unique Items to ListBox Dynamically

    Hi Experts.

    Please help me in following problem

    I have a userform which contains a Combo List Box and a List Box.

    In combo list box I have list of some products, like showing in coloumn C

    I want when I select any item from combo list box then
    List box load the list in list box only matched values in column C vs combo box.
    List box should remove duplicates rows. Only show unique values.

    Means every product have multiple rows with same value.
    listbox should show the unique value.

    I shall be very Thankful to you.

    Amir
    Attached Files Attached Files
    Don't wait for the PERFECT MOMENT
    take the moment and make it PERFECT
    Amir

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

    Re: Add unique Items to ListBox Dynamically

    Option Explicit
    
    Private dic As Object
    
    Private Sub UserForm_Initialize()
        Dim a, i As Long
        Set dic = CreateObject("Scripting.Dictionary")
        dic.CompareMode = 1
        a = Sheets("sheet1").Cells(1).CurrentRegion
        For i = 2 To UBound(a, 1)
            If Not dic.exists(a(i, 3)) Then
                Set dic(a(i, 3)) = CreateObject("Scripting.Dictionary")
            End If
            dic(a(i, 3))(a(i, 2)) = Array(a(i, 1), a(i, 2))
        Next
        Me.ComboBox1.List = dic.keys
    End Sub
    
    Private Sub ComboBox1_Change()
        Me.ListBox1.Clear
        With Me.ComboBox1
            If .ListIndex > -1 Then
                If dic(.Value).Count > 1 Then
                    Me.ListBox1.List = Application.Index(dic(.Value).items, 0, 0)
                Else
                    Me.ListBox1.Column = Application.Index(dic(.Value).items, 0, 0)
                End If
            End If
        End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    09-18-2014
    Location
    Pakistan
    MS-Off Ver
    2013, 2016
    Posts
    283

    Re: Add unique Items to ListBox Dynamically

    Thank you so much Jindon!
    Your code is working but not loading the column b.
    Please guide me how can I extend the range of listbox means with multiple columns.

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

    Re: Add unique Items to ListBox Dynamically

    Just change ColumnCount property to 2

  5. #5
    Forum Contributor
    Join Date
    09-18-2014
    Location
    Pakistan
    MS-Off Ver
    2013, 2016
    Posts
    283

    Re: Add unique Items to ListBox Dynamically

    Thank you so much. Jindon
    It really works.

    Can you tell me if I want to extend this code for more than two columns or column could be change like E and F then how can I?
    If you have time, its not to disturb you.

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

    Re: Add unique Items to ListBox Dynamically

            dic(a(i, 3))(a(i, 2)) = Array(a(i, 1), a(i, 2), a(i, 5), a(i, 6))

  7. #7
    Forum Contributor
    Join Date
    09-18-2014
    Location
    Pakistan
    MS-Off Ver
    2013, 2016
    Posts
    283

    Re: Add unique Items to ListBox Dynamically

    Thank you so much jindon.
    Really genius friend you are.

    Thanks Again
    Amir

+ 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] Loop find all matches of listbox items, display results in another listbox
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2015, 02:56 AM
  2. [SOLVED] Listbox with unique and dependent items - VBA
    By limalf in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-04-2014, 02:37 PM
  3. [SOLVED] Auto select items in a Listbox with items from another Listbox
    By perducci in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-22-2013, 04:45 PM
  4. 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
  5. Editing listbox items in Dblclick event freezes Excel unless mouse moves over listbox
    By muneebmansoor in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-28-2013, 02:21 PM
  6. Transfer random listbox items to new listbox and then loop through selected items
    By narrowgate88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2013, 05:58 PM
  7. [SOLVED] Setting up a validation of data listbox to provide the unique items within a range
    By jedale@gmail.com in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 07-30-2006, 04:10 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