I have book A with many columns and headings, I would like to separate this data and fill out book B based on the name of the heading (in book B there are 4 sheets of different pre-populated column headings)
1) Workbook A (many columns), filters for all its unique values in col 'AN' (i.e. col AN has 20 unique values, but ~ 3000 rows for each unique set).
2) There is book B with pre-filled columns on 4 sheets, and not all the same headings as in book A. Here, unique values from col AN from book A will be entered here with their corresponding entries, one after the other.
The goal is to populate these 4 sheets with data from book A, sorting for each unique value of column AN with its entries in pre-filled book B.
This code still uniquely filters my main column "AN" and just gets unique values, I need unique values along with the records.
Sub Sort()
Dim wb As Workbook, fileNames As Object, errCheck As Boolean
Dim ws As Worksheet, wks As Worksheet, wksSummary As Worksheet
Dim y As Range, intRow As Long, i As Integer
Dim r As Range, lr As Long, myrg As Range, z As Range
Dim boolWritten As Boolean, lngNextRow As Long
Dim intColNode As Integer, intColScenario As Integer
Dim intColNext As Integer, lngStartRow As Long
Dim lngLastNode As Long, lngLastScen As Long
' Finds column AN , header named 'first name'
intColScenario = 0
On Error Resume Next
intColScenario = WorksheetFunction.Match("First name", .Rows(1), 0)
On Error GoTo 0
If intColScenario > 0 Then
' Only action if there is data in column E
If Application.WorksheetFunction.CountA(.Columns(intColScenario)) > 1 Then
lr = .Cells(.Rows.Count, intColScenario).End(xlUp).Row
' Copy unique values from the formula column to the 'Unique data' sheet, and write sheet & file details
.Range(.Cells(1, intColScenario), .Cells(lr, intColScenario)).AdvancedFilter xlFilterCopy, , r, True
r.Offset(0, -2).Value = ws.Name
r.Offset(0, -3).Value = ws.Parent.Name
' Delete the column header copied to the list
r.Delete Shift:=xlUp
boolWritten = True
End If
End If
'I need to take the rest of the records with this though.
' Reset system settings
With Application
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
.Visible = True
End With
End Sub
Adding Sample Images
Workbook Sample, I want a unique filter "task column" to collect all related entries:

Workbook Example B, Sheet 1 (note that there will be multiple sheets). As you can see, book A was sorted by the "job" column.
