skull_eagle
Board Regular
- Joined
- Mar 25, 2011
- Messages
- 89
Hi,
I'm trying to filter a sheet using a userform, the user clicks a checkbox on the userform and the filter is applied immediately.
It was working fine until a number of columns need to be filtered with the word "Valid" instead of just not blank.
If the Checkbox is selected, check if that column already has a filter applied, if it does then clear the filter, If it doesn't apply the filter.
One filter should add the another filter, it should not clear it.
I'm hoping someone smarter than me can simplify this and make it reliable.
This is in a Class Module
I'm trying to filter a sheet using a userform, the user clicks a checkbox on the userform and the filter is applied immediately.
It was working fine until a number of columns need to be filtered with the word "Valid" instead of just not blank.
If the Checkbox is selected, check if that column already has a filter applied, if it does then clear the filter, If it doesn't apply the filter.
One filter should add the another filter, it should not clear it.
I'm hoping someone smarter than me can simplify this and make it reliable.
This is in a Class Module
VBA Code:
Private Sub mLabelGroup_Click()
Dim ControlName, ColNum
Dim Rowz As Long
Dim wsRD As Worksheet
Set wsRD = Worksheets("RawData")
Set wsRD = ActiveSheet
'On Error Resume Next
ControlName = mLabelGroup.Name
ColNum = Replace(ControlName, "CB_", "")
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="<>"
End If
If ColNum = 24 Then
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="Valid"
End If
End If
If ColNum = 27 Then
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="Valid"
End If
End If
If ColNum = 29 Then
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="Valid"
End If
End If
If ColNum = 65 Then
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="Valid"
End If
End If
If ColNum = 69 Then
If wsRD.AutoFilter.Filters(ColNum).On Then
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum
Else
ActiveSheet.ListObjects("Table_RawData").Range.AutoFilter Field:=ColNum, _
Criteria1:="Valid"
End If
End If
Rowz = wsRD.AutoFilter.Range.Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count - 1
Search_Form.Controls("Results_1").Caption = Rowz & " Results"
End Sub