It looks like this has been answered a while ago but I wanted to ask an additional question. Can you make this into a universal macro using some user input?
Public Sub xFilter()
Dim rng As Range
Dim tmp As String
Dim val()
Dim addr As String
Dim intStart As Long
Dim intEnd As Long
Dim intCol As Integer
Dim FilterLocation As Range
Dim FilterValues As Range
Set FilterLocation = Application.InputBox("Select Filter Location", "Obtain Range Object", Type:=8)
Set FilterValues = Application.InputBox("Selection: Filter Criteria", "Obtain Range Object", Type:=8)
Worksheets(FilterValues.Worksheet.Name).Select ' A worksheet with the filter (possible) values.
FilterValues.Select
Range(Selection, Selection.End(xlDown)).Select
Set rng = Selection ' get address
intStart = rng.Row
intEnd = intStart + (rng.Count - 1)
intCol = rng.Column ' next column
Set rng = Range(Cells(intStart, (intCol + 1)), Cells(intEnd, (intCol + 1)))
' convert to text
rng.FormulaR1C1 = "=Text(rc[-1],0)"
' convert to array of text
val = Application.Transpose(rng)
rng.FormulaR1C1 = "" ' remove formula
Set rng = Nothing
Worksheets(FilterLocation.Worksheet.Name).Select
FilterLocation.Select
Range(Selection, Selection.End(xlDown)).Select
Set rng = Selection
intStart = rng.Row
intEnd = intStart + (rng.Count - 1)
'intCol = rng.Column ' next column
'Range(Cells(intStart, 1), Cells(intEnd, 2)).AutoFilter
Range(Cells(intStart, 1), Cells(intEnd, 2)).AutoFilter _
Field:=1, Criteria1:=val, Operator:=xlFilterValues
End Sub
The only issue is that when I substitute this for the last row I get an error:
Range(Cells(intStart, 1), Cells(intEnd, 2)).AutoFilter _
Field:=FilterValues.Column, Criteria1:=val, Operator:=xlFilterValues