Hi,
I'm running different auto filters on my worksheet to search for specific text, one after the other. I first filter by date and then by keyword.
Excel crashes when there are no filtered rows / when it can't find the keyword in the worksheet.
Excel crashed so I didn't manage to save the exact code I was using but I've tried checking for the number of visible rows by using:
.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 = 0
thanks,
Tom
I'm running different auto filters on my worksheet to search for specific text, one after the other. I first filter by date and then by keyword.
Excel crashes when there are no filtered rows / when it can't find the keyword in the worksheet.
Excel crashed so I didn't manage to save the exact code I was using but I've tried checking for the number of visible rows by using:
.Columns(1).SpecialCells(xlCellTypeVisible).Count - 1 = 0
Code:
These are the filters that Excel is crashing on usually:
'Filter Data
If Criteria2 = "" Then
DataRange.AutoFilter Field:=AutoFilterField, Criteria1:="=" & Criteria1, Operator:=xlAnd
Else
'if filtering using 2 criteria then check if logical operator is and or or.
If Criteria2 <> "" And LogicalOperator = "xlAnd" Then
DataRange.AutoFilter Field:=AutoFilterField, Criteria1:="=" & Criteria1, Operator:=xlAnd, Criteria2:=Criteria2
ElseIf Criteria2 <> "" And LogicalOperator = "xlOr" Then
DataRange.AutoFilter Field:=AutoFilterField, Criteria1:="=" & Criteria1, Operator:=xlOr, Criteria2:=Criteria2
End If
End If
thanks,
Tom