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