+ Reply to Thread
Results 1 to 4 of 4

Add unique items in Listbox based on Combobox

Hybrid View

sunjam Add unique items in Listbox... 04-18-2017, 03:44 AM
LeoTaxi Re: Add unique items in... 04-18-2017, 05:29 AM
jindon Re: Add unique items in... 04-18-2017, 05:59 AM
sunjam Re: Add unique items in... 04-18-2017, 11:27 PM
  1. #1
    Registered User
    Join Date
    02-19-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2010
    Posts
    88

    Add unique items in Listbox based on Combobox

    Hi,

    I have this combobox that is populated by column A.

    And a Listbox that was populated based on combobox Vlookup from Column C.

    I need to add the unique items in column C to Listbox based on Combobox.

    Please see codes below.

    Dim c As Range, Variance As String
    ListBox1.Clear
    With Range("Order_list")
        Set c = .Find(Me.ComboBox1, LookIn:=xlValues)
        If Not c Is Nothing Then
            Variance = c.Address
            Do
                ListBox1.AddItem c.Offset(0, 1)
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> Variance
        End If
    End With
    Please help.

    Thank you.

  2. #2
    Forum Expert
    Join Date
    08-16-2015
    Location
    Antwerpen, Belgium
    MS-Off Ver
    2007-2016
    Posts
    2,380

    Re: Add unique items in Listbox based on Combobox

    Try with this, change sheet names

    Private Sub ComboBox1_Click()
    Dim c As Range, Variance As String
    ListBox1.Clear
    With Sheets("Blad1").Range("C:C")
        Set c = .Cells.Find(Me.ComboBox1, LookIn:=xlValues)
        If Not c Is Nothing Then
            Variance = c.Address
            Do
                If Application.CountIf(Sheets("blad1").Range("D1", "D" & c.Row), c.Offset(, 1)) = 1 Then
                    ListBox1.AddItem c.Offset(0, 1)
                End If
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> Variance
        End If
    End With
    End Sub
    Kind regards
    Leo

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

    Re: Add unique items in Listbox based on Combobox

    Try
    Dim c As Range, Variance As String, dic As Object
    Set dic = CreateOjbect("Scripting.Dictionary")
    dic.CompareMode = 1
    ListBox1.Clear
    With Range("Order_list")
        Set c = .Find(Me.ComboBox1, LookIn:=xlValues)
        If Not c Is Nothing Then
            Variance = c.Address
            Do
                dic(c.Offset(0, 1).Value) = Empty
                Set c = .FindNext(c)
            Loop While c.Address <> Variance
            ListBox1.List = dic.keys
        End If
    End With

  4. #4
    Registered User
    Join Date
    02-19-2013
    Location
    Cebu, Philippines
    MS-Off Ver
    Excel 2010
    Posts
    88

    Re: Add unique items in Listbox based on Combobox

    It works! Thank you LeoTaxi

+ 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] Count Unique Items in a Column Based on Unique Items in Two Other Columns
    By HangMan in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 10-31-2015, 04:48 PM
  2. [SOLVED] Unique items in combobox on userform
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-16-2015, 09:31 AM
  3. [SOLVED] Add unique Items to ListBox Dynamically
    By AmirSoft in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2015, 01:25 AM
  4. [SOLVED] Unique Items in a combobox
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-11-2015, 05:49 AM
  5. [SOLVED] Userform - ListBox items added based on Combobox value selected
    By jayherring86 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 11-12-2014, 09:12 AM
  6. [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
  7. Replies: 2
    Last Post: 12-07-2012, 02: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