Hello
I have created a sub to filter a table by one column, and sort alphabetically in ascending order by another column. This is what I've used:
Sub FilterSort()
'filter to show #N/As and sort by FromName column
Set FilteredNames = OutlookData.range("OutlookData[FromName]")
Set OutlookTable = OutlookData.ListObjects("OutlookData")
OutlookTable.range.AutoFilter Field:=2, Criteria1:="#N/A"
With OutlookTable.Sort
.SortFields.Clear
.SortFields.Add Key:=FilteredNames, Order:=xlAscending
.Apply
End With
End Sub
When I step through this code it works fine; column B is filtered to show just #N/As and column C (FromName) is sorted alphabetically. However when I call this sub from within another sub it doesn't work properly. Column C gets sorted alphabetically and column B remains unfiltered, despite the filter drop down bar showing that it has been filtered to show just #N/As.
The sub that contains this one (FilterSort) exports Outlook data, uses an INDEX MATCH formula to connect the data exported with a separate worksheet in the workbook, and then calls this sub to filter and sort that data, if that makes sense...
Why would the sub work on it's own but not within another sub? If anyone could help or point me in the right direction I would appreciate greatly. Can also provide more info if anything is unclear. Thanks
Bookmarks