I managed to resolve the issue
See my code below
Sub ExtractDataWithAdvancedFilter()
Dim wsImport As Worksheet, wsExtract As Worksheet
Dim criteriaRange As Range, copyToRange As Range
Dim lastRow As Long
' Set references to the sheets
Set wsImport = ThisWorkbook.Sheets("Imported Data")
Set wsExtract = ThisWorkbook.Sheets("Extract Specified Cols")
' Clear existing data in wsExtract from row 2
wsExtract.Range("A2:E" & wsExtract.Rows.Count).ClearContents
' Define the range for criteria (AA1:AA2 in wsExtract)
Set criteriaRange = wsExtract.Range("AA1:AA2")
' Determine the last row of data in wsImport
lastRow = wsImport.Cells(wsImport.Rows.Count, 1).End(xlUp).Row
' Define the range where the filtered data will be copied to (A1:E1 in wsExtract)
Set copyToRange = wsExtract.Range("A1:E1")
' Apply the advanced filter
wsImport.Range("A1:G" & lastRow).AdvancedFilter Action:=xlFilterCopy, _
criteriaRange:=criteriaRange, copyToRange:=copyToRange, Unique:=False
End Sub
Bookmarks