LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Code to capture filter settings works but not for color filters

Hi. Below is a snippet of code I came across on the internet that
works great for recording the current filter settings, allowing code
to run, and then resetting the filters, for anything filtered on
values at least. However, if a column is filtered by color, the macro
errors out. I'm fairly sure the error revolves around the Criteria or
Operator, but why would there be a difference, and what might I be
able to do to incorporate the color filtering so it doesn't error out?
Thanks!

wksQB.Select

' Capture AutoFilter settings
With wksQB.AutoFilter
currentFiltRange = .Range.Address
With .Filters
ReDim filterArray(1 To .Count, 1 To 4)
For f = 1 To .Count
With .Item(f)
If .On Then
filterArray(f, 1) = .Criteria1
If .Operator Then
filterArray(f, 2) = .Operator
End If
End If
End With
Next f
End With
End With

'Remove AutoFilter
wksQB.AutoFilterMode = False

' my other code goes here

RestoreFilters:
' Restore Filter settings
For col = 1 To UBound(filterArray(), 1)
If Not IsEmpty(filterArray(col, 1)) Then
If filterArray(col, 2) Then
wksQB.Range(currentFiltRange).AutoFilter Field:=col, _
Criteria1:=filterArray(col, 1), _
Operator:=filterArray(col, 2), _
Criteria2:=filterArray(col, 3)
Else
wksQB.Range(currentFiltRange).AutoFilter Field:=col, _
Criteria1:=filterArray(col, 1)
End If
End If
Next col


Here are 4 filters I've applied. All work with the code above to
unfilter and refilter, except the Criteria1:=RGB(0,176,80) with
Operator:=xlFilterCellColor.

Examples. Below shows 4 filters. All work except the
Operator:=xlFilterCellColor
ActiveSheet.Range("$A$1:$CI$3809").AutoFilter Field:=6,
Criteria1:= _ ' This works
"Bell, Francis"
ActiveSheet.Range("$A$1:$CI$3809").AutoFilter Field:=16,
Criteria1:=Array( _
"RemB Handswitch", "REMB HANDSWITCH - EUROPEAN", "Universal
Handswitch"), _
Operator:=xlFilterValues
ActiveSheet.Range("$A$1:$CI$3809").AutoFilter Field:=1,
Criteria1:="45", _
Operator:=xlAnd
ActiveSheet.Range("$A$1:$CI$3809").AutoFilter Field:=2,
Criteria1:=RGB(0, _
176, 80), Operator:=xlFilterCellColor
 
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
Excel filter won't capture everything in the column - why? The_Warden Excel Worksheet Functions 3 May 14th 08 05:10 PM
Auto Filter - capture criteria used Kolotti Excel Discussion (Misc queries) 2 January 30th 07 05:05 PM
Capture Find Settings Jim Thomlinson[_5_] Excel Programming 3 January 12th 06 02:30 AM
Capture Auto-Filter Change STEVE BELL Excel Programming 4 August 16th 05 01:36 AM
Color Code Filter indicators - Change from Blue to Red Martinson44 Excel Worksheet Functions 0 November 10th 04 04:25 AM


All times are GMT +1. The time now is 06:21 PM.

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"