98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Display filter criteria using macro buttons | Excel forum
Display filter criteria using macro buttons | Excel forum
Resolved · Urgent Priority · Version 2010
Sif has attended:
Excel Advanced course
Display filter criteria using macro buttons
Hi there
I have written simple macros to autofilter a table of data.
The code for one of them looks like this:
Sub Filter_Region()
Dim Crit1 As Range, bRange As Range
Set Crit1 = Range("I5")
Set bRange = Range("A10:O64")
With bRange
.AutoFilter field:=8, Criteria1:=Crit1.Value
End With
End Sub
These work fine, but I want to display the criteria by which I am filtering, so I have used a function written by someone called Stephen Bullen:
Function FilterCriteria(Rng As Range) As String
'By Stephen Bullen
Dim Filter As String
Filter = ""
On Error GoTo Finish
With Rng.Parent.AutoFilter
If Intersect(Rng, .Range) Is Nothing Then GoTo Finish
With .Filters(Rng.Column - .Range.Column + 1)
If Not .On Then GoTo Finish
Filter = .Criteria1
Select Case .Operator
Case xlAnd
Filter = Filter & " AND " & .Criteria2
Case xlOr
Filter = Filter & " OR " & .Criteria2
End Select
End With
End With
Finish:
FilterCriteria = Filter
Worksheets("Option 2").Calculate
End Function
I just have to write =showfilter(CELL REFERENCE) - which work fine until....
When I run my 'macro buttons' these display cells do not seem to update, instead I get a #VALUE! error.
I have tried putting =showfilter(F10)&LEFT(SUBTOTAL(9,D11:O64),0) to automatically update them, and also added Worksheets("NAME OF SHEET).Calculate to try to update these automatically but it doesn't work.
Help on detecting what the problem & how to fix these display cells would be fantastic!
Thank you
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Formst Excel to display leading zeroesSelect the cells that you want to have displaying leading zeroes. |