autofilter
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Autofilter

Autofilter

resolvedResolved · Low Priority · Version 2007

replyReply Thu 19 Jan 2012, 11:43Delegate Richard said...

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

For upcoming training course dates see: Pricing & availability

replyReply Fri 20 Jan 2012, 10:48Trainer Mark said...

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

 

Please browse our web site to find out more about
training ms excel advanced and other Microsoft training courses.

Excel tip:

Recovering Unsaved Work in Excel 2010

Ever closed your Excel workbook in a hurry without saving your work beforehand? Here's how to get it back.

Choose File then Info, click Manage Versions and then Recover Unsaved Workbooks which will automatically find the spreadsheets that haven't been saved.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard