Hi
I'm using the following code to search a worksheet for a userform combobox value:
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.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
Last edited by WCJanssen; 01-29-2011 at 11:26 AM.
Found a solution myself: the dropdownlist is re-arranged when you de- and reselect the combobox.
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:-
MickPrivate 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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks