Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

display filter criteria using

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Display filter criteria using macro buttons

Display filter criteria using macro buttons

ResolvedVersion 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

RE: Display filter criteria using macro buttons

Also I should add that when I click on the cell with the =showfilter formula, it updates, but I have to go in a click on it and press Enter, to remove the #VALUE! error.

 

Training courses

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Adding multiple rows in an Excel 2010 Worksheet

If you want to add more than one row to an Excel Worksheet, drag select the number or rows you want added to the spreadsheet.

Then right click on these selected rows, choose Insert from the menu, and the new rows will be added above the rows you first selected.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.09 secs.