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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
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,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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