I have a macro that works great, if I have a list in column B and a list in column C, it takes the two columns and aligns the matching items based on column B
I have attached an example of the macro in an excel file test.xlsm
Below is the code. I would like to change the code so that it will align the rest of the columns after C as well. So if there was information in column D it would move that as well when B and C are aligned.
Sub AlignedSort()
Dim iRow As Long
'sort the two columns ascending
Range("B2", [B65536].End(xlUp)).Sort Key1:=[b1]
Range("C2", [C65536].End(xlUp)).Sort Key1:=[c1]
iRow = 2
Do Until IsEmpty(Cells(iRow, 2)) Or IsEmpty(Cells(iRow, 3))
If Cells(iRow, 2) < Cells(iRow, 3) Then
Cells(iRow, 3).Insert xlShiftDown
ElseIf Cells(iRow, 2) > Cells(iRow, 3) Then
Cells(iRow, 2).Insert xlShiftDown
End If
iRow = iRow + 1
Loop
End Sub
THanks for any help
Bookmarks