+ Reply to Thread
Results 1 to 13 of 13

Adding items to Combobox

  1. #1
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Adding items to Combobox

    Hi All,

    In my excel sheet, from B2 to B20 i have datas like,

    aaa
    bbb
    ccc
    aaa
    ccc
    ddd
    rrr
    ttt
    bbb
    rrr
    ttt

    I want to add this to my combobox1 with out repeation as, 'aaa' should be listed in combobox once. What is the macro for this or we can do it in Combobox properties itself?

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Adding items to Combobox

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Question Re: Adding items to Combobox

    Hi Bob,

    I am new to macro.

    I am having the below values in A column of sheet1;
    aaa
    bbb
    ccc
    aaa
    ccc
    ddd
    rrr
    ttt

    If i have a combobox1 in Sheet1, what is the script to be included to add the unique values to combo box, is it 'Sheets(1).ComboBox1.AddItem ary(NextItem)'?

    In the script you said, where i have to insert it?

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding items to Combobox

    What kind of combobox re you suing , which menu did you insert from?
    Hope that helps.

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

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Adding items to Combobox

    I am using combobox from Control Toolbox.

    I am usng MS Office 2003.

  6. #6
    Registered User
    Join Date
    07-29-2009
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Adding items to Combobox

    here is the code
    Please Login or Register  to view this content.
    put this in worksheet.activate event
    Last edited by Leith Ross; 07-31-2009 at 02:30 AM. Reason: Added Code Tags

  7. #7
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Smile Re: Adding items to Combobox

    Hi Haissk,

    Thanks a lot Boss!

  8. #8
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Adding items to Combobox

    Hi,

    The script you given was working fine when data was like,
    aaa
    bbb
    ccc
    aaa
    bbb
    In combobox 'aaa' is gettng added only once, fine.

    But when i have data like,
    111
    222
    333
    222
    111
    For this when i use the same script datas in the column is getting repeated in combobox also, any idea?

  9. #9
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Adding items to Combobox

    This works fine

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Exclamation Re: Adding items to Combobox

    Hi Bob,

    In your script, you have not written the command to add those values to Combobox.

    Could you edit the script of yours adding the above thing?

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

    Re: Adding items to Combobox

    Hello randheerp,

    The combo box is loaded by this line in Bob's code...
    Please Login or Register  to view this content.
    If the name of your combo box isn't ComboBox1, you will need to change the name to match your combo box's name.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  12. #12
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Thumbs up Re: [Solved]Adding items to Combobox

    Thanks Mr. Bobs and also Ross...

    Actually i didn't notice the last line of Bob's script coz it was under the scroll bar.

    ThankU Bob once again.

  13. #13
    Registered User
    Join Date
    07-29-2009
    Location
    Bangalore
    MS-Off Ver
    Excel 2003
    Posts
    9

    Arrow Re: Adding items to Combobox

    Hi,

    My datas in A column is like,

    11
    22
    33

    44
    55

    I am having a row gap between 33 and 44.

    When i execute the below mentioned script, i my combobox i am getting up to 33. So that gap is causing problem.
    Please Login or Register  to view this content.
    What modification to be made on the above script to overcome the above mentioned issue?
    Last edited by Leith Ross; 08-03-2009 at 10:13 AM. Reason: Added Code Tags

+ 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