+ Reply to Thread
Results 1 to 3 of 3

Thread: How to select a item in a combobox?

  1. #1
    Registered User
    Join Date
    01-27-2011
    Location
    Brazil
    MS-Off Ver
    Excel 2007
    Posts
    72

    Exclamation How to select a item in a combobox?

    Hi, this code isn't working:
     ActiveCell.Offset(0, i).Text = ComboBox1.ListIndex(i).Text
    How to do it or something like:
    combobox1.text = Combobox1.item(i).text
    Ie, how to show a specific item in a combobox.

  2. #2
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: How to select a item in a combobox?

    if the combobox contains a 1-dimensional array and you want to get the 3rd item:

     
      ActiveCell.Offset(, 1) = ComboBox1.List(2)

    if the combobox contains a mulidimensional array and you want to get the 3rd item in the first column:
     
      ActiveCell.Offset(, 1) = ComboBox1.List(2,1)
    Last edited by snb; 09-01-2011 at 03:09 PM.



  3. #3
    Forum Guru Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    2003, 2007 and 2010
    Posts
    1,207

    Re: How to select a item in a combobox?

    To get the value from the Combobox, which is what it looks like you want to do because you are trying to assign it to a cell, you need the List property, not the ListIndex property.
    ActiveCell.Offset(0, i).Text = ComboBox1.List(i)
    To "pick" an item in the combobox, you use ListIndex.
    ComboBox1.ListIndex = 3
    Last edited by Colin Legg; 09-01-2011 at 01:05 PM.
    Hope that helps,

    Colin

    RAD Excel Blog

    Other tutorials:
    Array Formulas | Deleting Rows with VBA

+ 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.2.0