+ Reply to Thread
Results 1 to 3 of 3

Thread: combobox list squeezed into single line

  1. #1
    Registered User
    Join Date
    06-21-2009
    Location
    Rotterdam, The Netherlands
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Question combobox list squeezed into single line

    Hi

    I'm using the following code to search a worksheet for a userform combobox value:

    Private Sub cboExample_Change()
        Dim n As Integer
        Dim vFound As Range
        Dim ws As Worksheet
        Dim LastRow As Long
        On Error Resume Next
    
    For n = cboExample.ListCount - 1 To 0 Step -1
            cboExample.RemoveItem n
    Next n
    
    
    Set ws = Worksheets("Sheet1")
        
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
        
        For lloop = 1 To LastRow
            If Left(ws.Cells(lloop, "A"), Len(cboExample.Value)) = cboExample.Value Then
                Set vFound = ws.Cells(lloop, "A")
                With Me.cboExample
                    .AddItem vFound.Offset(0, 0).Value
                    .List(.ListCount - 1, 1) = vFound.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = vFound.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = vFound.Offset(0, 3).Value
                    
                End With
            End If
        Next lloop
    
    End Sub
    It works fine, exept that all searchresults are listed in the first row of the combobox list (please take a look at the attached example workbook). Anyone know how to solve this? Thanks in advance.
    Attached Files Attached Files
    Last edited by WCJanssen; 01-29-2011 at 11:26 AM.

  2. #2
    Registered User
    Join Date
    06-21-2009
    Location
    Rotterdam, The Netherlands
    MS-Off Ver
    Excel 2003, 2007
    Posts
    26

    Re: combobox list squeezed into single line

    Found a solution myself: the dropdownlist is re-arranged when you de- and reselect the combobox.

  3. #3
    Valued Forum Contributor MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    888

    Re: combobox list squeezed into single line

    It appears that you enter a value from your list and if that value is found, then the combobox is filled with the column values.
    You select an Item , that item has 4 columns and thats what you see.
    If you want those items shown vertically try this:-
    Private Sub cboExample_Change()
        Dim n As Integer
        Dim vFound As Range
        Dim ws As Worksheet
        Dim LastRow As Long
        Dim lloop As Integer
        On Error Resume Next
    
    For n = cboExample.ListCount - 1 To 0 Step -1
            cboExample.RemoveItem n
    Next n
    
    
    Set ws = Worksheets("Sheet1")
        
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
        
        For lloop = 1 To LastRow
            If Left(ws.Cells(lloop, "A"), Len(cboExample.Value)) = cboExample.Value Then
                Set vFound = ws.Cells(lloop, "A")
                With Me.cboExample
                     .AddItem vFound.Offset(0, 0).Value
                     .AddItem vFound.Offset(0, 1).Value
                     .AddItem vFound.Offset(0, 2).Value
                     .AddItem vFound.Offset(0, 3).Value
                    
                    
                    
    '                .List(.ListCount - 1, 1) = vFound.Offset(0, 1).Value
    '                .List(.ListCount - 1, 2) = vFound.Offset(0, 2).Value
    '                .List(.ListCount - 1, 3) = vFound.Offset(0, 3).Value
                    
                End With
            End If
        Next lloop
    
    End Sub
    Mick

+ 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