+ Reply to Thread
Results 1 to 12 of 12

dropdown box options

  1. #1
    Registered User
    Join Date
    06-26-2007
    Posts
    36

    dropdown box options

    Hi, i am currently designing a userform which has a drop-down box for user to choose from the options given. However, i would like to have in the box fields such as "--Subjects", "English", "Maths", "Science". In this way, the user will be shown a list of options of the different subjects for them to choose from as well as to clearly identify to them that these are the subjects available therefore the heading "--Subjects". I would also have to make sure that the user can only select "English", "Maths", "Science" and NOT "--Subjects". How should i go about doing this?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Froggy19,

    There are 2 ways to add information to a DropDown or ComboBox. One way is to "hard code" the entries, and the other is to use the ControlSource property to load the entries.

    Hard coding prevents the user from changing the entries. It also means you have to make change to your code if you want to expand the list.

    Using the ControlSource property makes changing the entries easier since they are taken from a worksheet range of cells. This allows you to exapnd the list more easily, but also means the user can potentially corrupt the entries as well.

    This example hard codes the entries into a combobox named ComboBox1 on UserForm1. The "--Subjects" is displayed after the ComboBox is loaded, but not again after the user has made a selection.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by Leith Ross
    Hello Froggy19,

    There are 2 ways to add information to a DropDown or ComboBox. One way is to "hard code" the entries, and the other is to use the ControlSource property to load the entries.

    Hard coding prevents the user from changing the entries. It also means you have to make change to your code if you want to expand the list.

    Using the ControlSource property makes changing the entries easier since they are taken from a worksheet range of cells. This allows you to exapnd the list more easily, but also means the user can potentially corrupt the entries as well.

    This example hard codes the entries into a combobox named ComboBox1 on UserForm1. The "--Subjects" is displayed after the ComboBox is loaded, but not again after the user has made a selection.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Leith,

    I know that it is possible to have column headers for the columns in a list box. You can make them visible by Listbox1.ColumnHeads = True but I don't know how to add any text to them. List, AddItem work only on list rows. Headers will be ideal solution to this problem. Because, as the name suggests, they are only headers and a user cannot select them as opposed to the list items. Could you tell us how to insert text in the headers?

    Thanks in advance.

    A V Veerkar
    Last edited by avveerkar; 07-07-2007 at 03:08 PM.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello A V Veerkar,

    Column headers are only available to a Control Toolbox ComboBox or Listbox when they are loaded from a Worksheet using the ListFillRange property. The first row of the range will be used for the headers provided you have set ColumnHeads property to true.

    Sincerely,
    Leith Ross

  5. #5
    Forum Contributor
    Join Date
    01-10-2006
    Location
    Ahmedabad, India
    MS-Off Ver
    Office 2000
    Posts
    346
    Quote Originally Posted by Leith Ross
    Hello A V Veerkar,

    Column headers are only available to a Control Toolbox ComboBox or Listbox when they are loaded from a Worksheet using the ListFillRange property. The first row of the range will be used for the headers provided you have set ColumnHeads property to true.

    Sincerely,
    Leith Ross
    Thanks a lot Leith

    A V Veerkar

  6. #6
    Registered User
    Join Date
    06-26-2007
    Posts
    36
    Hi Leith Ross,

    in my dropdown box, i am suppose to put the following in the order below:

    --Subjects
    English
    Maths
    Science
    --Teacher
    Kenneth
    Randin
    Elizabeth

    As such, for the particular dropdown box, they can only select either English, Maths, Science, Kenneth, Randin or Elizabeth but not "--Subjects" and "--Teacher". May i know how i can go about doing it and yet achieve this order should i want all of these in 1 field?

    Thank you.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Froggy19,

    Will you be using data from a worksheet to load the ComboBoxes? If so, what ranges will you be using for ComboBox1, and ComboBox2?

    Thanks,
    Leith Ross

  8. #8
    Registered User
    Join Date
    06-26-2007
    Posts
    36
    Hi Leith,

    currently in the combobox, i am using an array to store what i want the user to select from

    ComboBL.List() = Array("English", "Maths", "Science", "Radin", "Kenneth", "Elizabeth")

    But is just that my supervisor would want me to add "--Subjects" and "--Teacher" into the list as i guide for users and ensuring that they are not allowed to select them

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Froggy19,

    To accomplish your design goal, you will need to use 2 ComboBoxes. Here are the macros for each labeled "LoadCombBox1", and "LoadComboBox2".

    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross
    Last edited by Leith Ross; 07-11-2007 at 06:25 AM.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    This is one way
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  11. #11
    Registered User
    Join Date
    06-26-2007
    Posts
    36
    Hi Leith,

    but this way i will have 2 comboboxes. What i need is to put all of them into 1 combobox only.

    Thanks

  12. #12
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Quote Originally Posted by froggy19
    Hi Leith,

    but this way i will have 2 comboboxes. What i need is to put all of them into 1 combobox only.

    Thanks
    That's not the best way, but see my code.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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