• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Convert table to columms

yaelcohen

Member
Hello

Thanks for your help!

If I have a table that look like that:(attached also a file)

Person Name/year 2002 2003 2004 2005 2006
John 1 2 2 1 3
Jacob 1 3 2 4 3
Ab 5 6 8 9 12

How can I convert it to:

John 2002 1
John 2003 2
/
/
Ab 2002 5

How can I use formula for it?

Thanks a lot

Yael
 

Attachments

  • Example 16.xlsb
    7.7 KB · Views: 9
For the data provided
Code:
Sub test()
    Dim a, b, i As Long, ii As Long, n As Long
    a = Range("b2").CurrentRegion.Value
    ReDim b(1 To UBound(a, 1) * UBound(a, 2), 1 To 3)
    For i = 2 To UBound(a, 1)
        For ii = 2 To UBound(a, 2)
            n = n + 1
            b(n, 1) = a(i, 1): b(n, 2) = a(1, ii): b(n, 3) = a(i, ii)
    Next ii, i
    Range("o2").Resize(n, 3).Value = b
End Sub
 
Hi to all!

Another solution, with Power Query (I leave the video here - Excel in Spanish, but is easy to understand). I did the video in Excel 2016, but you can download the add-in Power Query if you have Excel 2010 or newer.

The advantage... is easy for updating (right click above results, update) and easy reply.

Blessings!
 

Attachments

  • example.rar
    1,004.5 KB · Views: 3

Thanks John Jairo !

I know how to achieve web scraping via VBA
but like demand is linked to Power Query …
 
Back
Top