Hi everyone,
First time poster, long time follower. I have been struggling hard with a particular VBA code.
I'm trying to take a column of data on a sheet (sheet1) and use it as filter criteria for a specific column on another sheet (Q1 2009) within the same workbook. I have code below that will cycle through each value with in the column and enter it into the criteria for the column on the filter sheet but it never retains the filter and just jumps to the next criteria so that the end result is Q1 2009 sheet is filtered by only the value from the last value within the column.
Can someone assist me in having the criteria the filter should use from worksheet "Sheet1" filter the data on "Q1 2009" worksheet? What I have so far is below:
First time poster, long time follower. I have been struggling hard with a particular VBA code.
I'm trying to take a column of data on a sheet (sheet1) and use it as filter criteria for a specific column on another sheet (Q1 2009) within the same workbook. I have code below that will cycle through each value with in the column and enter it into the criteria for the column on the filter sheet but it never retains the filter and just jumps to the next criteria so that the end result is Q1 2009 sheet is filtered by only the value from the last value within the column.
Can someone assist me in having the criteria the filter should use from worksheet "Sheet1" filter the data on "Q1 2009" worksheet? What I have so far is below:
Code:
Sub FilterListOrTableData()
Dim ACell As Range, ARange As Range
Dim FilterCriteria As String
Application.ScreenUpdating = False
'Check to see if the worksheet is protected.
If ActiveSheet.ProtectContents = True Then
MsgBox "This macro will not work when the worksheet is write-protected.", _
vbOKOnly, "Filter example"
Exit Sub
End If
Set ARange = Worksheets("Sheet1").Range("A1:A316")
For Each ACell In ARange
Worksheets("Q1 2009").ListObjects("Table1").Range.AutoFilter Field:=6, Criteria1:=ACell.Text
Next ACell
End Sub