display filter criteria using

Forum 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

resolvedResolved · 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

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:

Formst Excel to display leading zeroes

Select the cells that you want to have displaying leading zeroes.

From the 'Format' menu select 'Cells' (Or Right-click on the selected range and and select 'Format Cells').

In the 'Number' tab click on 'Custom' in the 'Category' window.

In the 'Type:' box enter zeroes that correspond to the size of the required number (eg 5 zeroes).

Click OK.

When you enter numbers into these cells, leading zeroes will be displayed.

eg 123 = 00123

View all Excel hints and tips


Server loaded in 0.07 secs.