Auto-filter question
In , Dana DeLouis
spake thusly:
I believe I can't have AutoFilter on in non-contiguous regions.
I'm pretty sure you can have only 1 autofilter per sheet.
Make sure you have a heading column spanning from Column C to
Column Y. Here I assume you have a heading Column from A:Y.
Would this general idea work for you?
Yes! I did get it to work. Thank you very much, Dana!
I have been driving myself crazy trying things.
That is great. I have a couple of questions, though.
First, I tried to figure out how to make it start with Column
C instead of Column A, but I didn't yet succeed. I can
live with it the way it is, but would like to know how.
Second, I already have a macro that gets called in the
same operation, which cycles through all the columns.
So I thought it would be economical and logical to combine
these functions. However, I can't get that to work, either.
The other macro does start with Column A and goes all the way to
the end -- right now, that's Column AD (30 columns). But I really
only need the AutoFilter in the range of Column C:Y, as I said.
In any case, it seems non-optimal to loop an extra time through all
the columns. How would I incorporate your algorithm into what I
have already? It is as follows:
Option Explicit
Sub HideCols()
Dim iCol As Long
Dim iLastCol As Long
With Application.ActiveSheet
iLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
For iCol = 1 To iLastCol
If .Cells(2, iCol).Interior.ColorIndex = 24 Then
.Columns(iCol).Hidden = True
Else
.Columns(iCol).Hidden = False
End If
'Debug.Print iCol
Next iCol
End With
End Sub
(Mainly that is the nice work-product of Dave Peterson.)
Thanks,
Dallman
================================================== ==============
Sub Demo()
Dim C As Range '(C)olumn
[A1].CurrentRegion.AutoFilter
With ActiveSheet.AutoFilter.Range
'// Turn off All Arrows
For Each C In .Columns
.AutoFilter Field:=C.Column, _
VisibleDropDown:=False
Next C
'// But have Drop down arrow for Column C
.AutoFilter Field:=3, VisibleDropDown:=True
'// Now Add Filters...
.AutoFilter Field:=25, _
Criteria1:="Test Value", _
VisibleDropDown:=False
End With
End Sub
|