+ Reply to Thread
Results 1 to 8 of 8

Combobox alternatives based on a range

  1. #1
    Registered User
    Join Date
    08-20-2009
    Location
    Stockholm,Sweden
    MS-Off Ver
    Excel 2003
    Posts
    43

    Combobox alternatives based on a range

    Hi,

    I have a simple but still very annoying problem...

    I have a list of persons, as in my dummybook. The list can contain any
    number of personons. I want to put all of the dates in a combobox as
    alternatives, but only one of each and no blank alternatives.

    So the combobox should contain unique values and no blank values!

    The combobox should also uppdate itself when a new post is added.

    How do I get this to work ?

    Many thanks!!

    //

    Per
    Attached Files Attached Files
    Last edited by Pero; 03-09-2011 at 09:24 AM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Combobox alternatives based on a range

    Hi Pero

    One way is to create a dynamic named range of the dates. Advanced Filter the date range (including the header) to sheet2 then name that range. See attached.

    Sorry, I left a piece of code out...I'll repost the workbook.
    Attached Files Attached Files
    Last edited by jaslake; 03-06-2011 at 05:42 PM.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    08-20-2009
    Location
    Stockholm,Sweden
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Combobox alternatives based on a range

    Hi,

    thanks for reply!

    It works but is there a way of doing this whithout copying the filter result to a new sheet and then add them to a combobox ? w
    It must be possible to write a VBA-code that adds all unique dates to a array and then add the array to the combobox or something ?
    Without any visual interaction!

    Thanks again!

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Combobox alternatives based on a range

    Hi Pero

    Actually, there is a way to do this
    It must be possible to write a VBA-code that adds all unique dates to a array
    and I worked with something like that recently. I'll need to dig through my scrap heap and see if I can give you an example.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Combobox alternatives based on a range

    Hi Pero

    Notice this Requires, Tools > Reference > Microsoft Scripting Runtime, scrrun.dll
    Place this code in a general module
    Please Login or Register  to view this content.
    Place this code in Sheet1
    Please Login or Register  to view this content.
    Let me know of issues.
    Last edited by jaslake; 03-06-2011 at 07:31 PM. Reason: Corrected Sheet Change Event Code

  6. #6
    Registered User
    Join Date
    08-20-2009
    Location
    Stockholm,Sweden
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Combobox alternatives based on a range

    Hi, Thanks ! Almost works..

    If the list only contains one personi get an error "Type missmatch" on
    line:
    Please Login or Register  to view this content.
    That must be because anArray is difined as a variant and when it only contains one element variant will choose "wrong" datatype for "anArray" and "For Each a in anArray" wont work.

    I'm I right ?


    EDIT:

    Also , the dates in the combobox are displayed in another format then in the actual list. The list contains dates in format YYYY-MM-DD but in the combobox list its : MM-DD-YYYY
    I want it to be YYYY-MM-DD in the combobox aswell!

    Thanks again !
    Last edited by Pero; 03-07-2011 at 12:15 PM.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Combobox alternatives based on a range

    Hi Pero

    Modify the code as follows
    Please Login or Register  to view this content.
    Let me know of issues.

  8. #8
    Registered User
    Join Date
    08-20-2009
    Location
    Stockholm,Sweden
    MS-Off Ver
    Excel 2003
    Posts
    43

    Re: Combobox alternatives based on a range

    It works =) .
    Thnaks you very much!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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