|
|
|
|
|
|
Excel
|
Highlight the columns being used to AutoFilter a range
|
|
Ease of Use
|
Easy
|
Version tested with
|
97, 2000, 2002, 2003
|
Submitted by:
|
byundt
|
Description:
|
As user picks one or more columns to AutoFilter some data, those columns will be highlighted. Turning AutoFilter off for those columns will unhighlight them.
|
Discussion:
|
If you are using the AutoFilter tool to filter data, it may be desirable to print the results and show (by highlight color) which columns were used in filtering. This will also serve as a reminder to the user if data manipulation is complex.
|
Code:
|
instructions for use
|
Private Sub Worksheet_Calculate()
ColorAutoFilter
End Sub
Sub ColorAutoFilter()
Dim FilterNum As Long
With ActiveSheet
If .AutoFilterMode Then
For FilterNum = 1 To .AutoFilter.Filters.Count
If .AutoFilter.Filters(FilterNum).On Then
.AutoFilter.Range.Columns(FilterNum).Interior.ColorIndex = 6
Else
.AutoFilter.Range.Columns(FilterNum).Interior.ColorIndex = xlNone
End If
Next
Else
.Cells.Interior.ColorIndex = xlNone
End If
End With
End Sub
|
How to use:
|
- Right-click the sheet tab of the worksheet containing the AutoFilter data.
- Choose "View Code" from the resulting pop-up.
- Paste the first sub (Worksheet_Calculate) in the resulting module sheet.
- Use the Insert...Module menu item to create a blank regular module sheet.
- Paste the ColorAutoFilter sub in this regular module sheet.
- Repeat steps 1-3 for any other worksheets containing AutoFilter data.
- Press Alt + Q to close the VBE.
- At least one cell on the worksheet containing the AutoFilter must be volatile?see discussion in "Test the code" below.
- Save workbook before any other changes.
|
Test the code:
|
- This code is triggered by the recalculation of any cell on the worksheet. You can force a recalculation after performing an AutoFilter by the "trick" of including at least one volatile cell in your worksheet?such as cell I1 in the sample workbook. A volatile cell has a formula using volatile functions like NOW, TODAY, OFFSET, INDIRECT, RAND, INFO or CELL (except when CELL uses the "filename" parameter).
- Make sure that your data has header labels above each column.
- Select the data to be AutoFiltered, including the header labels.
- Open the Data...Filter...AutoFilter menu item to turn the AutoFilter on.
- Click the arrow at right of one of the header labels to apply a filter. That column should then become highlighted yellow.
- Click the arrow at right of another header label and apply a filter to that column too. Now two columns should be highlighted yellow.
- Click arrow on the first column header label and choose (All). That column will now become unhighlighted.
|
Sample File:
|
HighlightAutoFilterColumn.zip 8.09KB
|
Approved by mdmackillop
|
This entry has been viewed 164 times.
|
|