I
icestationzbra
hi,
i have a query regarding the UDF 'showfilter' that i found on debra'
website. this function is used to highlight a filter that is currentl
on. the function returns a value to a cell. that value is then used i
conditional formatting to change the colour of the cell containing th
filter that is active.
i was wondering if there is a way we could use the 'showfilter
function directly in conditional formatting 'formula is' field. i
would reduce the number of steps down to one.
i was also not able to understand a few lines from the code. if someon
would be benevolent enough to explain it to me, i would be grateful.
Set sh = rng.Parent
If Intersect(rng.EntireColumn, frng) Is Nothing Then
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
Set filt = sh.AutoFilter.Filters(lngOff)
i also wanted to know if i could use a range of cells while comparin
'target' in the selectionchange event. that is, currently i hav
graduated to using 'target.row=2' and 'target.column=3' to check fo
cell 'C2'. is there a way to check if C2 (or the activecell) falls i
the range 'A1:C10'? i was not able to figure out by myself.
*****
the whole code is pasted below, with due credit to the author:
*****
Public Function ShowFilter(rng As Range)
'UDF that displays the filter criteria.
'posted by Tom Ogilvy 1/17/02
'To make it respond to a filter change, tie it to the subtota
command.
'=showfilter(B2)&CHAR(SUBTOTAL(9,B3)*0+32)
'So the above would show the criteria for column B
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet
Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range
If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function
*****
thanks,
mac
i have a query regarding the UDF 'showfilter' that i found on debra'
website. this function is used to highlight a filter that is currentl
on. the function returns a value to a cell. that value is then used i
conditional formatting to change the colour of the cell containing th
filter that is active.
i was wondering if there is a way we could use the 'showfilter
function directly in conditional formatting 'formula is' field. i
would reduce the number of steps down to one.
i was also not able to understand a few lines from the code. if someon
would be benevolent enough to explain it to me, i would be grateful.
Set sh = rng.Parent
If Intersect(rng.EntireColumn, frng) Is Nothing Then
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
Set filt = sh.AutoFilter.Filters(lngOff)
i also wanted to know if i could use a range of cells while comparin
'target' in the selectionchange event. that is, currently i hav
graduated to using 'target.row=2' and 'target.column=3' to check fo
cell 'C2'. is there a way to check if C2 (or the activecell) falls i
the range 'A1:C10'? i was not able to figure out by myself.
*****
the whole code is pasted below, with due credit to the author:
*****
Public Function ShowFilter(rng As Range)
'UDF that displays the filter criteria.
'posted by Tom Ogilvy 1/17/02
'To make it respond to a filter change, tie it to the subtota
command.
'=showfilter(B2)&CHAR(SUBTOTAL(9,B3)*0+32)
'So the above would show the criteria for column B
Dim filt As Filter
Dim sCrit1 As String
Dim sCrit2 As String
Dim sop As String
Dim lngOp As Long
Dim lngOff As Long
Dim frng As Range
Dim sh As Worksheet
Set sh = rng.Parent
If sh.FilterMode = False Then
ShowFilter = "No Active Filter"
Exit Function
End If
Set frng = sh.AutoFilter.Range
If Intersect(rng.EntireColumn, frng) Is Nothing Then
ShowFilter = CVErr(xlErrRef)
Else
lngOff = rng.Column - frng.Columns(1).Column + 1
If Not sh.AutoFilter.Filters(lngOff).On Then
ShowFilter = "No Conditions"
Else
Set filt = sh.AutoFilter.Filters(lngOff)
On Error Resume Next
sCrit1 = filt.Criteria1
sCrit2 = filt.Criteria2
lngOp = filt.Operator
If lngOp = xlAnd Then
sop = " And "
ElseIf lngOp = xlOr Then
sop = " or "
Else
sop = ""
End If
ShowFilter = sCrit1 & sop & sCrit2
End If
End If
End Function
*****
thanks,
mac