Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,564
- Office Version
- 365
- 2016
- Platform
- Windows
I have a multiselect listbox (uf1_listbox2) in my userform (uf1_assess_sched).
It has 2 columns, one holding text, the other a number.
I am trying to generate a list on a worksheet (to form a criteria range for an advanced filter) of the values selected from the listbox.
This code seems to do the trick, however, I do not want to include any selection in the criteria range if the number value (2nd column) of the selection in the listbox is 0.
How can I exclude selected rows from the listbox whose second column value = 0? Or, prevent the user from selecting any rows from the listbox in the first place in which column 2 = 0?
It has 2 columns, one holding text, the other a number.
I am trying to generate a list on a worksheet (to form a criteria range for an advanced filter) of the values selected from the listbox.
Code:
Private Sub cbtn_clean_Click()
Dim temp_ws As Worksheet
Dim afh_col As Integer, i As Integer, icount As Integer
Set temp_ws = Workbooks("schedule.csv").Worksheets("temp_ws")
'check if anything selected
For i = 0 To uf1_listbox2.ListCount - 1
If uf1_listbox2.Selected(i) = True Then
icount = icount + 1
End If
Next i
If icount = 0 Then
MsgBox "Please make a selection before trying to clean.", vbInformation, "ERROR: No selections"
Exit Sub
End If
'create advanced filter list
afh_col = 1 'starting point of advanced filter criteria range
For i = 0 To uf1_listbox2.ListCount - 1
If uf1_listbox2.Selected(i) = True Then
If uf1_listbox2.List(i) = "Reference" Then
r_type = "ref"
ElseIf uf1_listbox2.List(i) = "Function" Then
r_type = "fcn"
ElseIf uf1_listbox2.List(i) = "Facility" Then
r_type = "fac"
ElseIf uf1_listbox2.List(i) = "Unid'd Class" Then
r_type = "X"
Else
r_type = "X2"
End If
'advanced filter criteria range
ws_vh.Cells(10, afh_col).Value = r_type
afh_col = afh_col + 1
End If
Next i
End Sub
This code seems to do the trick, however, I do not want to include any selection in the criteria range if the number value (2nd column) of the selection in the listbox is 0.
How can I exclude selected rows from the listbox whose second column value = 0? Or, prevent the user from selecting any rows from the listbox in the first place in which column 2 = 0?
Last edited: