Custom filter

  • Thread starter Thread starter Cimjet
  • Start date Start date
Hi Isabelle
I would need your help again if possible.
I've solved some of the problems but I would like to be able to have a worksheet
with nothing in it.
This is my macro. Something like "If range A5:B5 is nothing then next"
Sub Filter()
Dim wsh As Worksheet
For Each wsh In Worksheets
With wsh
If wsh.Range("K3").Value = "Global" Then
If Not .FilterMode Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:=">=" & Range("F1").Value2, _
Operator:=xlAnd, Criteria2:="<=" & Range("G1").Value2
End If
End With
Next
End Sub
Best regards
Cimjet
 
hi Cimjet ,

Sub Filter()
Dim wsh As Worksheet
For Each wsh In Worksheets
With wsh
If wsh.Range("K3").Value = "Global" Then
If Not .FilterMode And Not Application.CountA(Range("A5:B5")) < 2 Then .Range("B5").AutoFilter
.Range("B5").AutoFilter , Field:=2, Criteria1:=">=" & Range("F1").Value2, _
Operator:=xlAnd, Criteria2:="<=" & Range("G1").Value2
End If
End With
Next
End Sub
 
Thank you Isabelle, that works great, but the "Remove filter" still has the
problem.
I tried this but without success.
Sub RemoveFilter()
Dim wsh As Worksheet
For Each wsh In Worksheets
With wsh
'.Range("B5").AutoFilter
If Not .FilterMode And Not Application.CountA(Range("A5:B5")) < 2 Then
..Range("B5").AutoFilter
End With
Next
End Sub
Regards
Cimjet
 
Thank you Isabelle, that works great, but the "Remove filter" still has the
problem.
I tried this but without success.
Sub RemoveFilter()
Dim wsh As Worksheet
For Each wsh In Worksheets
With wsh
'.Range("B5").AutoFilter
If Not .FilterMode And Not Application.CountA(Range("A5:B5")) < 2 Then
..Range("B5").AutoFilter
End With
Next
End Sub
Regards
Cimjet
 
hi Cimjet,

without the file, a test isn't possible, I let you test


Sub Filter()
Dim wsh As Worksheet
For Each wsh In Worksheets
With wsh
If wsh.Range("K3").Value = "Global" Then
If Not .FilterMode Then .Range("B5").AutoFilter
If Not Application.CountA(Range("A5:B5")) < 2 Then
.Range("B5").AutoFilter , Field:=2, Criteria1:=">=" & Range("F1").Value2, _
Operator:=xlAnd, Criteria2:="<=" & Range("G1").Value2
End If
End If
End With
Next
End Sub
 
Back
Top