Trasponer valore duplicados de columnas a filas

Tengo una hoja con dos columnas en las que hay datos duplicados:

Col1 Col2

A              1

A              2

A              3

B              1

C              2

C              3 

Y necesito exponerlos en filas:

Col1    Col2  Col3   Col4

A            1        2        3

B            1

C            2       3

C            2

1 respuesta

Respuesta
-1
Sub TranponerDatos()
    Set h1 = Sheets("Hoja1")
    Set h2 = Sheets("Hoja2")
    h2.Cells.Clear
    '
    For i = 2 To h1.Range("A" & Rows.Count).End(xlUp).Row
        Set b = h2.Rows(1).Find(h1.Cells(i, "A"), LookAt:=xlPart)
        If Not b Is Nothing Then
            col = b.Column
            u = h2.Cells(Rows.Count, b.Column).End(xlUp).Row + 1
            h1.Cells(i, "B").Copy h2.Cells(u, b.Column)
        Else
            uc = h2.Cells(1, Columns.Count).End(xlToLeft).Column + 1
            If h2.Cells(1, uc - 1) = "" Then uc = 1
            h1.Cells(i, "A").Copy h2.Cells(1, uc)
            h1.Cells(i, "B").Copy h2.Cells(2, uc)
        End If
    Next
End Sub

Cambia en la macro "Hoja1" por el nombre que tiene los datos.

Cambia "Hoja2" por la hoja de destino

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas