Te mando una macro, te va a ordenar por códigos, puedes tener las parejas de columnas código, dato, hacia la derecha, todas las que necesites.
Al final te va a crear una hoja nueva con la tabla nueva ordenada.
La hoja con tu información se debe llamar “Hoja1”, si quieres cambiarle el nombre, puedes modificar la macro, reemplazar “Hoja1” por el nuevo.
Instrucciones
1. Abre tu hoja de excel
2. Para abrir Vba-macros y poder pegar la macro, Presiona ALt + F11
3. En el menú elige Insertar / Módulo
4. En el panel del lado derecho copia la macro
5. Para ejecutarla presiona F5
'***Macro***
Sub ordenarcodigos()
'Ordena codigos de filas a columnas
'Por.dam
Application.ScreenUpdating = False
hojacodigos = "Hoja1"
Worksheets(hojacodigos).Select
ufil = ActiveCell.SpecialCells(xlLastCell).Row
ucol = ActiveCell.SpecialCells(xlLastCell).Column
Worksheets.Add
hojasalida = ActiveSheet.Name
ufilsalida = ActiveCell.SpecialCells(xlLastCell).Row
ucolsalida = ActiveCell.SpecialCells(xlLastCell).Column
Worksheets.Add
hojaordena = ActiveSheet.Name
ufilordena = ActiveCell.SpecialCells(xlLastCell).Row
ucolordena = ActiveCell.SpecialCells(xlLastCell).Column
Worksheets(hojacodigos).Select
j = 1
For i = 1 To ucol
Range(Cells(2, j), Cells(ufil, j + 1)).Select
Range(Cells(2, j), Cells(ufil, j + 1)).Copy
Worksheets(hojaordena).Select
Cells(ufilordena, 1).Select
ActiveSheet.Paste
ufilordena = ActiveCell.SpecialCells(xlLastCell).Row
ucolordena = ActiveCell.SpecialCells(xlLastCell).Column
ufilordena = ufilordena + 1
Worksheets(hojacodigos).Select
j = j + 2
i = i + 1
Next
Worksheets(hojaordena).Select
Columns("A:B").Select
Application.CutCopyMode = False
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, DataOption2 _
:=xlSortNormal
unavez = 1
For i = 1 To ufilordena
If unavez = 1 Then
inicio = i
unavez = 2
codant = Cells(i, 1)
Else
codnvo = Cells(i, 1)
If codant = codnvo Then
final = i
Else
Range(Cells(inicio, 2), Cells(final, 2)).Select
Range(Cells(inicio, 2), Cells(final, 2)).Copy
Worksheets(hojasalida).Select
Cells(1, ucolsalida).Value = codant
Cells(2, ucolsalida).Select
ActiveSheet.Paste
ufilsalida = ActiveCell.SpecialCells(xlLastCell).Row
ucolsalida = ActiveCell.SpecialCells(xlLastCell).Column
ucolsalida = ucolsalida + 1
Worksheets(hojaordena).Select
inicio = i
codant = codnvo
End If
End If
Next
Worksheets(hojasalida).Select
Rows("1:1").Select
With Selection.Font
.Name = "Arial"
.FontStyle = "Negrita"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Application.DisplayAlerts = False
Worksheets(hojaordena).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
'***Macro***
Saludos.dam