Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Restore Autofilter After Macro Runs

Hello,

I have a sheet with autofilter. I need to turn off the autofilter
before a macro runs but then I need to return it to the original
condition (i.e. only original filtered rows are shown). How can I
record the autofilter criteria and the field number in order to
restore the original selected autofilter?

Thanks very much in advance for any help!

Best Regards,
Emily
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Restore Autofilter After Macro Runs

There's some pretty good information about AutoFilter he
http://www.ozgrid.com/VBA/autofilter-vba.htm
combine that with what you can find in the VB Help on AutoFilter and you end
up building something like this:

Sub SetAndResetAutoFilter()
Dim filterState As Boolean
Dim filterRangeAddress As String
Dim fc As Long ' to work through possible filter fields
Dim filterField As Long
Dim filterCriteria1 As Variant

If ActiveSheet.FilterMode Then
'remember that .FilterMode is true
filterState = True
With ActiveSheet
For fc = 1 To .AutoFilter.Filters.Count
If .AutoFilter.Filters(fc).On Then
filterField = fc
Exit For
End If
Next
filterRangeAddress = .AutoFilter.Range.Address
filterCriteria1 = .AutoFilter.Filters(filterField).Criteria1
'now show all data; turns .FilterMode off
.ShowAllData
End With
End If

MsgBox "Do other stuff here while all data is visible"

'now we set things back the way they were
If filterState Then
ActiveSheet.Range(filterRangeAddress).AutoFilter _
Field:=filterField, _
Criteria1:=filterCriteria1
End If

End Sub


"emilyyy" wrote:

Hello,

I have a sheet with autofilter. I need to turn off the autofilter
before a macro runs but then I need to return it to the original
condition (i.e. only original filtered rows are shown). How can I
record the autofilter criteria and the field number in order to
restore the original selected autofilter?

Thanks very much in advance for any help!

Best Regards,
Emily

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs Rruffpaw Setting up and Configuration of Excel 1 September 17th 11 01:25 PM
Macro runs upon wkbk open, but no Workbook_Open or Auto_Open Macro Ron Coderre Excel Programming 2 September 26th 06 05:50 PM
One macro runs then it auto runs another macro PG Excel Discussion (Misc queries) 2 September 1st 06 09:30 PM
Macro runs in source , but not when in Personal Macro Workbook Darin Kramer Excel Programming 1 September 13th 05 04:48 PM
Restore Macro Speed Chris Excel Programming 1 October 15th 03 07:08 PM


All times are GMT +1. The time now is 04:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"