+ Reply to Thread
Results 1 to 3 of 3

Multicolumn combobox

  1. #1
    Registered User
    Join Date
    09-19-2003
    Posts
    9

    Multicolumn combobox

    In his blog, **** Kusleika gives this code for populating a listbox. It assumes the listbox has been set to to have a column count of 3, and that there is data in columns A, B and C of Sheet 1. I've checked the code and it works fine. However, I've tried using the same code to populate a combobox, but it doesn't seem to work. Anyone any idea why?

    Thanks, G

    Private Sub UserForm_Initialize()
    Dim cell As Range
    Dim Rng As Range

    With ThisWorkbook.Sheets(”Sheet1″)
    Set Rng = .Range(”A2″, .Range(”A2″).End(xlDown))
    End With

    For Each cell In Rng.Cells
    With Me.ListBox1
    .AddItem cell.Value
    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
    End With
    Next cell

    End Sub

  2. #2
    Patrick Molloy
    Guest

    RE: Multicolumn combobox

    Option Explicit
    Private Sub UserForm_Initialize()
    Dim cell As Range

    With ComboBox1

    For Each cell In Range("MyData").Columns(1).Cells
    .AddItem cell.Value
    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
    Next cell

    End With

    End Sub

    "Gromit" wrote:

    >
    > In his blog, **** Kusleika gives this code for populating a listbox. It
    > assumes the listbox has been set to to have a column count of 3, and
    > that there is data in columns A, B and C of Sheet 1. I've checked the
    > code and it works fine. However, I've tried using the same code to
    > populate a combobox, but it doesn't seem to work. Anyone any idea why?
    >
    > Thanks, G
    >
    > Private Sub UserForm_Initialize()
    > Dim cell As Range
    > Dim Rng As Range
    >
    > With ThisWorkbook.Sheets(ā€¯Sheet1ā€³)
    > Set Rng = .Range(ā€¯A2ā€³, .Range(ā€¯A2ā€³).End(xlDown))
    > End With
    >
    > For Each cell In Rng.Cells
    > With Me.ListBox1
    > .AddItem cell.Value
    > .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
    > .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
    > End With
    > Next cell
    >
    > End Sub
    >
    >
    > --
    > Gromit
    > ------------------------------------------------------------------------
    > Gromit's Profile: http://www.excelforum.com/member.php...nfo&userid=928
    > View this thread: http://www.excelforum.com/showthread...hreadid=503936
    >
    >


  3. #3
    Registered User
    Join Date
    09-19-2003
    Posts
    9
    Thanks Patrick,

    This works fine, thanks. I tried ****'s again for the 5th time, and this time it works also. I must have been doing something stupid.

    Thanks again,

    Graham

+ 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