Results 1 to 5 of 5

Listbox with unique and dependent items - VBA

Threaded View

limalf Listbox with unique and... 09-25-2013, 04:34 PM
tehneXus Re: Listbox with unique and... 09-25-2013, 04:44 PM
limalf Re: Listbox with unique and... 09-25-2013, 05:24 PM
AlphaFrog Re: Listbox with unique and... 09-25-2013, 05:08 PM
icemanroh Re: Listbox with unique and... 02-04-2014, 02:37 PM
  1. #1
    Registered User
    Join Date
    09-13-2013
    Location
    Porto, Portugal
    MS-Off Ver
    Excel 2010
    Posts
    17

    Listbox with unique and dependent items - VBA

    Hi,

    Sorry if this is a topic well discussed, but I have been working on this basic code to have it doing this:

    I have a Listbox1 in which I was able to populate it with unique items (from columnB in Programmes worksheet) using a collection (that was a good achievement for me!)

    Now, I want to populate a the Listbox2 with items (not repeated) from columnC, BUT only if the correspondent value on columnB is equal to listbox1.value.
    Could you please help me finding a solution for this? I am just a beginner in VBA...

    THANKS!

    <script type="text/javascript">
    <!--
    
    Private Sub CommandButton2_Click()
    
    Dim myList As Collection
    Dim myVal As Variant
    
    Set Programmes = Worksheets("Programmes")
    Set ws = Worksheets("Tables")
    Set myList = New Collection
    
    'Clear listbox
    ws.ListBox2.Clear
    
    'Last used cell in the entry table
    LR = Programmes.Cells(Rows.Count, 1).End(xlUp).Row
    
    
    For X = 5 To LR
        Set myCell = Programmes.Cells(X, 3)
        If Programmes.Cells(X, 2) = ws.ListBox1.Value Then
             myList.Add (myCell.Value), CStr(myCell.Value) 'RUN-TIME ERROR 457 - this key is already associated with an element of this collection
        End If
           
    Next X
    On Error GoTo 0
    
    For Each myVal In myList
    ws.ListBox2.AddItem myVal
    Next myVal
    
    End Sub
    
    //-->
    </script>
    Last edited by limalf; 09-25-2013 at 05:16 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [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
  2. 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
  3. 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
  4. 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
  5. [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

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