Custom filter

C

Cimjet

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
 
I

isabelle

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
 
C

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
 
C

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
 
I

isabelle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top