vb to Unselect a Filter Value
Thanks for all the help... I simplied the code a bit... No need to have the
extra error checks at this time...
Here were the resulting lines....
colNumber = Columns("D").Column
ActiveSheet.Cells.AutoFilter field:=colNumber, Criteria1:="<C"
Thank you for the education. I have just earned one brain cell back.
Don
"OssieMac" wrote:
I was not sure of exactly what you wanted. Anyway the code I gave you tests
all columns in the AutoFilter range. The following just tests column G.
I have assigned the column number of G to a variable. However, you need to
realize that this only works if the Autofilter columns start at column A
because the number required in the code is the number of the column in
Autofilter; not necessarily the worksheet column number. If say you have say
3 blank columns to the left of the autofiltered data then column 7 of the
Autofiltered data would not match column 7 of the worksheet and you would
need to specifically assign the autofilter column number to the variable.
As per my earlier comment, feel free to get back to me again if still not
what you want.
Sub FilterExample_4()
Dim ws As Worksheet
Dim strFilter As String
Dim colNumber As Long
'Convert column alpha Id to numeric
'Assumes that Autofilter columns start
'at column A.
colNumber = Columns("G").Column
Set ws = Worksheets("Sheet1")
With ws
'Test that AutoFilter is turned on
'(If turned off remaining code errors)
If .AutoFilterMode Then
'Test if filter colNumber is applied
With .AutoFilter
If .Filters(colNumber).On Then
'Assign filter value to variable
strFilter = .Filters(colNumber).Criteria1
If UCase(strFilter) = "=C" Then
'Turn off filter colNumber
.Range.AutoFilter Field:=colNumber
End If
End If
End With
Else
MsgBox "Autofilter is not turned on"
End If
End With
End Sub
--
Regards,
OssieMac
|