Hi all - I've got this piece of code to change the colour of the header cell being filtered on in a spreadsheet (you click the cell to filter, and it changes colour - makes it easier for users to spot which cell is filtered - the little blue arrow isn't always obvious apparently). Anyway, the code works fine; however, it keeps firing, so the function is constantly running. This makes it practically impossible to copy data between sheets and workbooks; switching between workbooks means minimising one before maximising another. Has anyone got any ideas how to get the function to only fire when a sheet is filtered, or have an alternative to what I have already?


Function AutoFilterOn(Rng As Range) As Boolean

'need conditional formatting on filter header cells with formula =AUTOFILTERON(xy)
'where xy is the cell reference

Application.Volatile True


If Rng.Worksheet.AutoFilterMode = False Then
    AutoFilterOn = False
ElseIf Intersect(Rng, Rng.Worksheet.AutoFilter.Range) Is Nothing Then
    AutoFilterOn = False
Else
    With Rng.Worksheet.AutoFilter
        AutoFilterOn = .Filters(Rng.Column - .Range.Column + 1).On
    End With
End If

End Function


Thanks in advance