Macro para pasar listado vertical a horizontal

Buenas Noches. Tengo unos datos mas de 8000 registros como este ejemplo:

REFERENCIA CODIGO UBICACIÓN

A0007A 0007 D01E09C

A0007A 0007 D01E18A

A0007A 0007 D01E19C

A0014A 0014 CART

A0014A 0014 D01E08E

A0014A 0014 D01E18A

A0014A 0014 D01E18B

A0014A24 0014 CART

.......... Etc

Como ven que las referencias se repiten porque tienen diferentes ubicaciones, necesito que una macro busque en un listado asi vertical referencias y me las consolide horizontalmente asi:

REFERENCIA UBICA 1 UBICA 2 UBICA 3 UBICA 4 UBICA 5 UBICA 6 .... Etc

A0007A D01E09C D01E18A D01E19C

A0014A CART D01E08E D01E18A D01E18B

A0014A24 CART D01E05D D01E16C

..... Etc

Porfavor ayudenme, con esta macro, gracias

1 respuesta

Respuesta
1

Te paso la solución, sigue mis pasos en este ejemplo:

-Tenemos esa tabla ocupando el rango A1:¿C? (Siendo la primera fila el encabezado y la coordenada de C la que sea)

-Ejecuta esta macro y todo listo:

Sub ejemplo()'por luismondelobuena = 0Range("a2").SelectDo While ActiveCell.Value <> ""ubica = ActiveCell.Addressfila = ActiveCell.Rowvalor = ActiveCell.Valuecontarsi = Application.WorksheetFunction.CountIf(Columns(ActiveCell.Column), valor)ActiveCell.Copy Destination:=Range("e65000").End(xlUp).Offset(1, 0)Range(Cells(fila, 3), Cells(fila + contarsi - 1, 3)).CopyRange("f65000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues, Transpose:=TrueRange(ubica).SelectDo While ActiveCell.Value = valorActiveCell.Offset(1, 0).SelectLoopLoopRange("a1").Copy Destination:=Range("e1")Range("f2").SelectDo While ActiveCell.Value <> ""maxima = Application.WorksheetFunction.CountA(Range(ActiveCell, ActiveCell.End(xlToRight)))If maxima > buena Thenbuena = maximaEnd IfActiveCell.Offset(1, 0).SelectLoopRange("f1").SelectFor c = 1 To buenaActiveCell.Value = "ubica" & cActiveCell.Offset(0, 1).SelectNextEnd Sub

recuerda finalizar

Parece que la web no funciona bien y copia la macro en una sola línea. Te la vuelvo a enviar:

Sub ejemplo()
'por luismondelo
buena = 0
Range("a2").Select
Do While ActiveCell.Value <> ""
ubica = ActiveCell.Address
fila = ActiveCell.Row
valor = ActiveCell.Value
contarsi = Application.WorksheetFunction.CountIf(Columns(ActiveCell.Column), valor)
ActiveCell.Copy Destination:=Range("e65000").End(xlUp).Offset(1, 0)
Range(Cells(fila, 3), Cells(fila + contarsi - 1, 3)).Copy
Range("f65000").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues, Transpose:=True
Range(ubica).Select
Do While ActiveCell.Value = valor
ActiveCell.Offset(1, 0).Select
Loop
Loop
Range("a1").Copy Destination:=Range("e1")
Range("f2").Select
Do While ActiveCell.Value <> ""
maxima = Application.WorksheetFunction.CountA(Range(ActiveCell, ActiveCell.End(xlToRight)))
If maxima > buena Then
buena = maxima
End If
ActiveCell.Offset(1, 0).Select
Loop
Range("f1").Select
For c = 1 To buena
ActiveCell.Value = "ubica" & c
ActiveCell.Offset(0, 1).Select
Next
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas