+ Reply to Thread
Results 1 to 4 of 4

Adding items to ComboBox in a loop?

  1. #1
    Registered User
    Join Date
    04-12-2006
    Posts
    35

    Adding items to ComboBox in a loop?

    Using vb comboBox is it possible to add the same items to numerous comboBox on the same sheet?
    I have been trying the following....

    Dim mycntrl As OLEObject
    Dim sht As Worksheet
    Set sht = ActiveSheet

    For Each mycntrl In sht.OLEObjects

    mycntrl.addItem "item1"

    Next mycntrl

    However I noticed that the addItem method is not available when trying this, so how would you add an item in a loop?

    thank you in advance for any help

  2. #2
    Doug Glancy
    Guest

    Re: Adding items to ComboBox in a loop?

    cmpcwil2,

    This syntax is difficult for me to remember, but I think this is what you
    want:

    Dim mycntrl As OLEObject
    Dim sht As Worksheet

    Set sht = ActiveSheet
    For Each mycntrl In sht.OLEObjects
    If TypeOf mycntrl.Object Is ComboBox Then
    mycntrl.Object.AddItem "item1"
    End If
    Next mycntrl

    hth,

    Doug


    "cmpcwil2" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Using vb comboBox is it possible to add the same items to numerous
    > comboBox on the same sheet?
    > I have been trying the following....
    >
    > Dim mycntrl As OLEObject
    > Dim sht As Worksheet
    > Set sht = ActiveSheet
    >
    > For Each mycntrl In sht.OLEObjects
    >
    > mycntrl.addItem "item1"
    >
    > Next mycntrl
    >
    > However I noticed that the addItem method is not available when trying
    > this, so how would you add an item in a loop?
    >
    > thank you in advance for any help
    >
    >
    > --
    > cmpcwil2
    > ------------------------------------------------------------------------
    > cmpcwil2's Profile:
    > http://www.excelforum.com/member.php...o&userid=33411
    > View this thread: http://www.excelforum.com/showthread...hreadid=538425
    >




  3. #3
    Tom Ogilvy
    Guest

    RE: Adding items to ComboBox in a loop?

    Dim mycntrl As OLEObject
    Dim sht As Worksheet
    Set sht = ActiveSheet

    For Each mycntrl In sht.OLEObjects
    if typeof mycntrl.object is MSforms.Combobox then
    mycntrl.Object.addItem "item1"
    end if

    Next mycntrl

    --
    Regards,
    Tom Ogilvy


    --
    Regards,
    Tom Ogilvy



    "cmpcwil2" wrote:

    >
    > Using vb comboBox is it possible to add the same items to numerous
    > comboBox on the same sheet?
    > I have been trying the following....
    >
    > Dim mycntrl As OLEObject
    > Dim sht As Worksheet
    > Set sht = ActiveSheet
    >
    > For Each mycntrl In sht.OLEObjects
    >
    > mycntrl.addItem "item1"
    >
    > Next mycntrl
    >
    > However I noticed that the addItem method is not available when trying
    > this, so how would you add an item in a loop?
    >
    > thank you in advance for any help
    >
    >
    > --
    > cmpcwil2
    > ------------------------------------------------------------------------
    > cmpcwil2's Profile: http://www.excelforum.com/member.php...o&userid=33411
    > View this thread: http://www.excelforum.com/showthread...hreadid=538425
    >
    >


  4. #4
    Registered User
    Join Date
    04-12-2006
    Posts
    35
    Thank you for you help

+ 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