+ Reply to Thread
Results 1 to 10 of 10

Populate ComboBox with unique and Visible from column B

  1. #1
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Post Populate ComboBox with unique and Visible from column B

    Excel 2010, VBA Userform with ComboBox

    I am able to populate ComboBox2 with the Filtered and visible data but, it also includes duplicates. How can I populate ComboBox2 with no duplicate data and only with the Visible data after its filtered.

    Below is code that I am using:

    'The Data has already been filtered and the combo displays the Filtered and visible data. I just need to remove the duplicates

    Set rng = .Range("AllData").Columns(2).SpecialCells(xlCellTypeVisible)
    For Each cel In rng

    With Me.ComboBox2
    .AddItem cel.Offset(0, 0).Value

    End With


    Any help is appreciated.
    Regards

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,485

    Re: Populate ComboBox with unique and Visible from column B

    Attaching a sample workbook enables others to work on your problem:

    To attach a sample workbook. Make sure there is just enough data to make it clear what is needed. Include BEFORE/AFTER sheets if needed to show the process you're trying to complete or automate. Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

    To add a file to a new post

    To add a file to an existing post.

  3. #3
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Populate ComboBox with unique and Visible from column B

    Hi davesexcel-

    Thank you for responding and the additional information.

    I have attached the excel file and a word doc with screenshots. Please let me know if additional info is needed.

    Regards,
    Attached Files Attached Files

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Populate ComboBox with unique and Visible from column B

    To get unique items in combobox take a look at Dictionarys.
    http://www.snb-vba.eu/VBA_Dictionary_en.html

  5. #5
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Populate ComboBox with unique and Visible from column B

    Hi bakerman2-

    I will take a look at Dictionary's.

    Thanks and regards,

  6. #6
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Populate ComboBox with unique and Visible from column B

    bakerman2 is correct, and provides an excellent tutorial link. Using a 'Scripting Dictionary' is an excellent way to implement what you want. A 'Scripting Dictionary' is a very good way to identify the unique items in a list.

    Unfortunately, the link is an excellent reference, but not very good if you have no Scripting Dictionary experience.

    You should be able to integrate the following code (tested with your file and working) into your routine that populates the ComboBox.
    Please Login or Register  to view this content.
    Lewis

  7. #7
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Populate ComboBox with unique and Visible from column B

    Hi LJMetzger-

    Thank you!

    I added the code for each Combo box and they are working. The only issue I have is that the Expiration date is showing up as numbers and not in the date format.

    Please see attachment.

    Regards,
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Populate ComboBox with unique and Visible from column B

    Hi,

    Excel displays dates in formats that we select that is usually easy for us to read, such as '08/08/2015". Internally Excel stores the dates as numbers. The VBA code extracted the date as a number, and we had to use the format statement to put the date back into prettyprint.

    UserForms have no idea what a number is. Everything in a UserForm is stored as text.


    Try the macro now. Changes in red:
    Please Login or Register  to view this content.
    Lewis

  9. #9
    Registered User
    Join Date
    06-04-2014
    Posts
    7

    Re: Populate ComboBox with unique and Visible from column B

    The modification has fixed it.

    Thank you again LJMetzger for your time.

    Thanks to all.

    Resolved.

    Regards,

  10. #10
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Populate ComboBox with unique and Visible from column B

    I'm glad you solved your problem. I was only too happy to help.

+ 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. populate a combobox based on unique values in another workbook
    By roninn75 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-03-2013, 03:36 AM
  2. Count unique, visible values in a filtered column
    By kajakk in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-07-2013, 08:42 AM
  3. [SOLVED] Populate ComboBox from a column excluding duplicates?
    By jfoerch in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2013, 02:06 PM
  4. Populate ComboBox from column of Excel Table
    By trecie13 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-14-2013, 10:32 AM
  5. Populate Combobox using column headers
    By jberr in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 06-28-2010, 09:36 AM
  6. Replies: 2
    Last Post: 09-14-2009, 08:34 AM
  7. how to populate a combobox with a list of unique values?
    By RIOSGER in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2005, 12:05 AM
  8. Populate unique list in combobox
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-26-2005, 05:05 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