transpose columns to rows

I would like to do this programatically :
I have this sheet1:

1        111         222      
2        666          67        
3         321       234    

I would like to run code/function/macro whatever to be able to have the result:

1   CODE1  111
1   CODE2  222
2   CODE1  666
2   CODE2  67
3   CODE1  321
3   CODE2  234
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ProfessorJimJamMicrosoft Excel ExpertCommented:
you can easily do this with free Add-in Power Query

see the tutorial
Have you tried Paste>Transpose?
drtopservAuthor Commented:
appretiate another solution becuase i can`t install power-query at this time , my computer don`t have explorer 9 .
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

drtopservAuthor Commented:
Paste>Transpose? will do :
1        111         222      
 2        666          67        
 3         321       234    

ID           1        2          3
CODE1  111    666      321
CODE2   222   67         234
ProfessorJimJamMicrosoft Excel ExpertCommented:
then you can use the attached VBA solution.

run the macro "CallUnPivotBySQL" then follow

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Saurabh Singh TeotiaCommented:
Use this code...

Sub arrangedata()
    Dim rng As Range, cell As Range
    Dim lrow As Long, lcol As Long
    Dim ws As Worksheet, ws1 As Worksheet
    Dim k As Long, lr1 As Long

    Set ws = Sheets("Sheet1")
    Set ws1 = Sheets("Sheet2")

    lrow = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row
    lcol = ws.Cells(1, Cells.Columns.Count).End(xlToLeft).Column

    Set rng = ws.Range("A2:a" & lrow)
    ws.Range("A1").Copy ws1.Range("A1")

    For Each cell In rng
        k = 2
        Do Until k > lcol
            lr1 = ws1.Cells(Cells.Rows.Count, "a").End(xlUp).Row + 1
            ws1.Cells(lr1, "a").Value = cell.Value
            ws1.Cells(lr1, "B").Value = ws.Cells(1, k).Value
            ws1.Cells(lr1, "C").Value = ws.Cells(cell.Row, k).Value
            k = k + 1

    Next cell

End Sub

Open in new window

This will move data from sheet1 to sheet2 in the desired format..Enclosed is the workbook for your reference..

Saqib Husain, SyedEngineerCommented:
Without code

If your given data starts from A1 on sheet1 then use this formula on A2 Sheet2 and copy it down and across

drtopservAuthor Commented:
ProfessorJimJamMicrosoft Excel ExpertCommented:
you are welcome. i am glad i was able to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.