Combobox/listbox List property doesn't work with 1 item

ashley12

New Member
Joined
Dec 6, 2020
Messages
43
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I'm trying to create a running search bar in my userform. Below is my code. SupplierInfo is the search list. wsSearch is a worksheet where the filtered list will be pasted to.
Everything work until the result list only has 1 item. Then it would give an error message as in the attached image. I tried combobox and list box, both have the same problem. Do you know how to fix it or have better way to achieve the result?

Thank you

VBA Code:
Private Sub CBSupName_Change()
    SupplierInfo.Activate
    SupplierInfo.ListObjects(1).DataBodyRange.AutoFilter Field:=1, Criteria1:="=*" & CBSupName.Value & "*", Operator:=xlAnd

    wsSearch.UsedRange.ClearContents
    SupplierInfo.ListObjects(1).DataBodyRange.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    wsSearch.Activate
    ActiveSheet.Range("A1").Select
    wsSearch.Paste
    wsSearch.Activate
    CBSupName.List = Selection.Value
    CBSupName.DropDown
End Sub

1621476398395.png
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
VBA Code:
   wsSearch.Activate
   If Selection.Rows.Count = 1 Then
      x = Array(Selection.Value)
   Else:
      x = Selection.Value
   End If
   CBSupName.List = x
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top