View Full Version : Filter 2 specific columns?


laxster
12-30-2009, 10:51 AM
Is it possible to allow AutoFilter arrows to only show up on two columns. I only want people to be able to filter columns E & G of a worksheet, but it seems like I can AutoFilter either one column or all of the columns. Is there code that could do this for me?

ajetrumpet
12-30-2009, 11:55 AM
i'm not sure if you can, but you can certainly write code and put a combo box on top of a cell and then hide the rows with a loop that doesn't match the selection. it's a long way to go, but it will work.

HaHoBe
12-30-2009, 11:45 PM
Hi, laxster,

mark only cells E1 and F1 and call the autofilter or use
Range("E1:F1").AutoFilter
in VBA after checking about FiulterMode.

Ciao,
Holger

chergh
12-31-2009, 12:30 AM
You can only autofilter a single range so you will have to rearrange your spreadsheet layout so the columns you want to autofilter are adjacent.

HaHoBe
12-31-2009, 01:57 AM
Hi, chergh,

youŽre right about the adjacent columns regarding the manual use of the autofilter. But using VBA IŽd take this road:

Sub ApplyAutofiterToColumns_E_And_G()

Dim rngCell As Range
Application.ScreenUpdating = False

'assuming that the Filter is to be set in the first row of the active sheet
If Not ActiveSheet.AutoFilterMode Then
Range(Cells(1, 1), Cells(1, Cells(1, 1).End(xlToRight).Column)).AutoFilter
End If
For Each rngCell In Range(Cells(1, 1), Cells(1, Cells(1, 1).End(xlToRight).Column))
Select Case rngCell.Column
Case 5, 7
Case Else
rngCell.AutoFilter Field:=rngCell.Column, Visibledropdown:=False
End Select
Next rngCell

Application.ScreenUpdating = True

End Sub
Ciao,
Holger

chergh
12-31-2009, 02:37 AM
I like that, hiding the dropdown is nice solution.