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

autofilter

ResolvedVersion 2007

Richard has attended:
Excel VBA Intro Intermediate course

Autofilter

Hi,

I have written code to remove a filter from a sheet, copy paste special values a selection, and then reapply the filter according to a value in a certain cell.

The only problem I have is when there is no filter applied before running the macro, it doesn't seem to work. Is there an 'If' I can put in to check whether the filter is applied and remove if it is, but if not just carry on with the paste special values?

The code is currently:

Sheets("ARIEL UK").Select
Selection.AutoFilter
Range("O9:U794").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Range("z9:z794").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
Range("Ac9:ac794").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues
ActiveSheet.Range("$A$2:$AE$794").Select
Selection.AutoFilter Field:=2, Criteria1:=Range("A1").Value
Application.CutCopyMode = False
Range("E2").Select

Many thanks

Rich

RE: Autofilter

Hello Rich,

You could try this IF styatement, it will check if autofilter is on or off.
If ActiveSheet.AutoFilterMode = True Then

(put your regular code here)

Else

(put your code here to turn on autofilter)

End If



I hope this resolves your question. If it has, please mark this question as resolved.

If you require further assistance, please reply to this post. Or perhaps you have another Microsoft Office question?

Have a great day.
Regards,

Mark
Microsoft Office Specialist Trainer

 

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:

Shortcut for accessing recently opened files

To get into recently opened Excel files without using your mouse, hold down Alt + F to open the File menu.

Recently opened files are listed down the bottom of the File menu - type in the number next to the file you wish to open and it should appear on your screen.

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.1 secs.