Ensuring Autofilter arrows are visible at end of macro

G

Guest

Hi,

I've been struggling with this one for a while -- I have a spreadsheet where
the user may or not have the Autofilter arrows being displayed prior to
running a macro. I always want to have the Autofilter arrows displayed for
all columns with values in Row 1 when the macro completes, regardless of if
the Autofilter arrows were on display prior to the person running the macro.
Below is the code I have tried, but I am getting an error (See error message
below). Any help is appreciated!

Error:
Run-time error '1004: AutoFiler method of Range class failed

Code:
With Sheets("Patent data with family data")

If .FilterMode Then
.ShowAllData
Else
.Range("A1:V1").AutoFilter VisibleDropDown:=True
End If

End With
 
D

Dave Peterson

Sometimes your code needs to see all the data.

So I turn off the autofilter, do the work, and reapply data|Filter|autofilter

With Sheets("Patent data with family data")

.autofiltermode = false

'do the work

'apply the autofilter to all the columns in the used range
.usedrange.columns.autofilter

End With
 
G

Guest

Try:
..Range("A1:V1").AutoFilter Field:=1, VisibleDropDown:=True
instead of:
..Range("A1:V1").AutoFilter VisibleDropDown:=True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top