Results 1 to 6 of 6

Loading MultiColumn Combobox in a Userform

Threaded View

  1. #1
    Registered User
    Join Date
    11-15-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2007
    Posts
    97

    Loading MultiColumn Combobox in a Userform

    Hi,

    I am trying to load a multicolumn combobox with the following code

    ' load all open work orders in a multi-column combobox
        Dim MyArray As Variant, tRow As Long, cRow As Long, d As Integer
        tRow = Worksheets("WO").Range("A" & Rows.Count).End(xlUp).Row
        If tRow > 2 Then
            ReDim MyArray(1 To 4, 1 To tRow - 2)   ' declare MyArray as a dynamic array
        
            ' define the properties of the combobox
            With Me.RcptCmbWoNo
                .ColumnCount = 4
                .ListWidth = 320
                .ListRows = 6
                .ColumnWidths = "20;60;200;40"
            End With
        
            ' populate the combobox
            d = 1
            For cRow = 3 To tRow + 1
                If Worksheets("WO").Cells(cRow, 23).Value > 0 Then
                    MyArray(1, d) = Worksheets("WO").Cells(cRow, 1).Value
                    MyArray(2, d) = Worksheets("WO").Cells(cRow, 3).Value
                    MyArray(3, d) = Worksheets("WO").Cells(cRow, 4).Value
                    MyArray(4, d) = Worksheets("WO").Cells(cRow, 23).Value
                    d = d + 1
                End If
            Next cRow
            ReDim Preserve MyArray(1 To 4, 1 To d - 1)
            ' populate the combobox
            If d > 0 Then
                RcptCmbWoNo.List() = Application.Transpose(MyArray)
            Else
                MsgBox "There are no work orders to display !"
                MainMenu
                Unload RcptForm
            End If
        Else
            MsgBox "There are no work orders to display !"
            MainMenu
            Unload RcptForm
        End If
    End Sub
    As you would see I am loading columns 1,3,4 and 23 from worksheet "WO" if the value in column 23 is greater than 0. The first two rows of this worksheet contain the header information. The data starts from row 3 onwards. This code works most of the time except that I am facing two situations as under:

    a) If there is no data in the worksheet (last used row is 2), I get "Run-time error '91': Object variable or With block variable not set." I get the same error if there is data but none fit the criterion "column 23 > 0".

    b) if there are 2 or more records to be displayed in the combobox, the information is displayed correctly in the columns. However, if there is only one record, each column is displayed one below the other as a row and I am able to select any row.

    I have been trying to get over this problem but do not seem to find the right solution.

    Would be grateful if some one can point out why I getting these problems and edit the code suitably for me.

    Thanks in advance,

    Anand Hattangady
    Last edited by anandvh; 01-22-2014 at 06:28 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Working with too many combobox multicolumn.
    By nuclearspy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-08-2012, 07:21 PM
  2. Multicolumn Combobox
    By hydrojoe11 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2008, 01:27 PM
  3. Multicolumn combobox
    By Gromit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2006, 12:14 PM
  4. [SOLVED] MultiColumn ComboBox
    By Paul Smith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-03-2005, 02:05 AM
  5. [SOLVED] MultiColumn ComboBox Value set/display
    By Jim Zeeb in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-13-2005, 05:05 AM

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