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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,223,888
Messages
6,175,217
Members
452,619
Latest member
Shiv1198

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