Filtering listbox with combobox text

baha17

Board Regular
Joined
May 12, 2010
Messages
181
HI Everybody,

I have a data sheet which has the skill codes of our staff in the casino. These are gaming skills such as; BJ,MD,NBC and so on
I have a comboboxes which filters the data in the listbox list which works under "listbox.change" event. Whenever I change the combobox text to let say "BJ" (black jack; I know eveybody likes this game:)) all the staff who does not have "BJ" skill will be removed from the list.It works partially fine upto now. Just recently I start adding N infront to identify the newly coded staff. So if the staff is just recently trained BJ it will appear NBJ. But now, when I change the combo text to "BJ", staff who has "NBJ" are also removed from list box. I have around 20 game skills and I do not want to write all possible scenarios as select case, I am hoping some of you excel masters can give me a hand over here. Belowis my code in combo change event, thank you for the help
Baha
Code:
Private Sub StaffSrchCB_Change()
    Dim N&
    Dim vListData
    Dim gtype As Variant
    Dim gtypeCol As Long
    Dim cel As Range
    Dim LastRow As Long
    gtype = StaffSrchCB.Value
    On Error Resume Next
    gtypeCol = Application.WorksheetFunction.Match(gtype, Sheets("Staff").Range("A1:W1"), 0) - 1
    
   'Exit Sub
   
    LastRow = Sheets("Staff").Range("A65536").End(xlUp).Row
    
    If StaffSrchCB.Text = "All" Or StaffSrchCB.Text = "" Then
    StaffSrchCB2 = ""
    SchTimeCB = ""
    PosCB = ""
    StaffSrchCB = ""
    AllStaffLB.Clear
    vListData = Worksheets("Staff").Range("A2:U" & LastRow)
    StafRepUF.AllStaffLB.List = vListData
    Else
    
    With AllStaffLB
    Select Case Len(StaffSrchCB.Text)
    Case Is = 3
    For N = (.ListCount - 1) To 0 Step -1
        If Left(UCase(.List(N, gtypeCol)), 3) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
    Next
    Case Else
    For N = (.ListCount - 1) To 0 Step -1
        If Left(UCase(.List(N, gtypeCol)), 2) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
    Next
    End Select
    End With
    
    End If
End Sub
 

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.
Hi,
I figured out by my self.Sorry for disturbance....

Private Sub StaffSrchCB_Change()
Dim N&
Dim vListData
Dim gtype As Variant
Dim gtypeCol As Long
Dim cel As Range
Dim LastRow As Long
gtype = StaffSrchCB.Value
On Error Resume Next
gtypeCol = Application.WorksheetFunction.Match(gtype, Sheets("Staff").Range("A1:W1"), 0) - 1

'Exit Sub

LastRow = Sheets("Staff").Range("A65536").End(xlUp).Row

If StaffSrchCB.Text = "All" Or StaffSrchCB.Text = "" Then
StaffSrchCB2 = ""
SchTimeCB = ""
PosCB = ""
StaffSrchCB = ""
AllStaffLB.Clear
vListData = Worksheets("Staff").Range("A2:U" & LastRow)
StafRepUF.AllStaffLB.List = vListData
Else

With AllStaffLB
Select Case Len(StaffSrchCB.Text)
Case Is = 3
For N = (.ListCount - 1) To 0 Step -1
Select Case Left(UCase(.List(N, gtypeCol)), 1)
Case Is = "N"
If Mid(UCase(.List(N, gtypeCol)), 2, 3) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
Case Else
If Left(UCase(.List(N, gtypeCol)), 3) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
End Select
Next
Case Else
For N = (.ListCount - 1) To 0 Step -1
Select Case Left(UCase(.List(N, gtypeCol)), 1)
Case Is = "N"
If Mid(UCase(.List(N, gtypeCol)), 2, 2) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
Case Else
If Left(UCase(.List(N, gtypeCol)), 2) <> UCase(StaffSrchCB.Text) Then .RemoveItem (N)
End Select
Next
End Select
End With

End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,631
Members
449,241
Latest member
NoniJ

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