98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Autofilter
Autofilter
Resolved · Low Priority · Version 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 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
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Display Formulas Instead of Results in Excel 2010By pressing Ctrl ~ once, Excel will display formulas rather than the results of the formulas. Press it again, and the results will appear again. |