Macro Help --- Transpose Row To Column

joi3288

New Member
Joined
Mar 14, 2011
Messages
11
Hi all,

I have this data in my spreadsheet:

item | image1 | image2 | image3 | image4 | image5
guitar-1 | k_g_1.png | b_g_1.jpg | e_g_1.jpg | e_g_2.jpg | e_g_3.jpg
guitar-2 | k_h_1.png | b_h_1.jpg | e_h_1.jpg | e_h_2.jpg | e_h_3.jpg

*I have more than a hundred rows on my spreadsheet here.

I want it to appear it this way.
guitar-1 | k_g_1.png
guitar-1 | b_g_1.jpg
guitar-1 | e_g_1.jpg
guitar-1 | e_g_2.jpg
guitar-1 | e_g_3.jpg
guitar-2 | k_h_1.png
guitar-2 | b_h_1.jpg
guitar-2 | e_h_1.jpg
guitar-2 | e_h_2.jpg
guitar-2 | e_h_3.jpg

You can place these columns maybe to Columns H and I.

Thanks.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi,

Code:
Sub kTest()
    Dim ka, k(), i As Long, j As Long, n As Long
    ka = [a1].CurrentRegion
    ReDim k(1 To UBound(ka, 1) * UBound(ka, 2), 1 To 2)
    
    For i = 2 To UBound(ka, 1)
        For j = 2 To UBound(ka, 2)
            n = n + 1
            k(n, 1) = ka(i, 1): k(n, 2) = ka(i, j)
        Next
    Next
    If n Then
        Columns("a:b").Insert
        [a1].Resize(, 2).Value = [{"Item","Image"}]
        [a2].Resize(n, 2).Value = k
    End If
End Sub

HTH
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top