Сайт, кажется, не работает ... к счастью, я сохранил полезный VB в прошлом году
Option Explicit Sub LineEmUp() 'Author: Jerry Beaucaire 'Date: 7/5/2010 'Summary: Line up a random number of columns so all matching ' items are on the same rows Dim LC As Long Dim Col As Long Dim LR As Long Application.ScreenUpdating = False 'Spot last column of data LC = Cells(1, Columns.Count).End(xlToLeft).Column 'Add new key column to collect unique values Cells(1, LC + 1) = "Key" For Col = 1 To LC Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _ Cells(Rows.Count, LC + 1).End(xlUp).Offset(1) Next Col Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes 'Fill in new table headers w/formatting Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3) 'Fill in new table values LR = Cells(Rows.Count, LC + 2).End(xlUp).Row With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC)) .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _ & "],0)), RC" & LC + 2 & ", """")" .Value = .Value End With 'Cleanup/Erase old values Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft Columns.Autofit Application.ScreenUpdating = True End Sub