Name the data sheet Data.
Name an empty sheet Output.
Run this macro:
Option Explicit
Sub FilterData()
Dim LC As Long, LR As Long, dCol As Long
Dim wsData As Worksheet, wsOut As Worksheet
Application.ScreenUpdating = False
Set wsData = Sheets("Data")
Set wsOut = Sheets("Output")
'Clear existing output sheet
wsOut.Cells.Clear
'Create sorted list of headers on Output sheet using Adv Filter
With wsData
.Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("C1"), Unique:=True
LR = .Range("C" & .Rows.Count).End(xlUp).Row
.Range("C2:C" & LR).Sort Key1:=.Range("C2"), Order1:=xlAscending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers
.Range("C2:C" & LR).Copy
wsOut.Range("A1").PasteSpecial Paste:=xlPasteAll, Transpose:=True
.Range("C1:C" & LR).ClearContents
LR = .Range("B" & .Rows.Count).End(xlUp).Row
End With
'Gather the data into each column
LC = wsOut.Cells(1, Columns.Count).End(xlToLeft).Column
For dCol = 1 To LC
wsData.Range("A:A").AutoFilter Field:=1, Criteria1:=wsOut.Cells(1, dCol)
wsData.Range("B2:B" & LR).SpecialCells(xlCellTypeVisible).Copy wsOut.Cells(2, dCol)
Next dCol
wsData.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
The simple things (?) here we are using are Advanced Filter/Sort to get the unique values, and copy/paste/transpose to put them in a row as headers.
Then we are using the AUTOFILTER on the column A to display all the rows of each header value one at a time. Then we copy the filtered results to the columns in sequence. Copying is only taking visible cells.
Bookmarks