moving columns and row data in excel

id like to move data around in my excel file. how can i do it using vba?

i have data in col a -d

some rows have only data in col a, others only data in col a,b, others with data only in col a,b,c and others with  data in a,b,c,d

i need the output file to make x # of rows for each row

cola           b       c     d
handle     6       43   106

so it would become
handle  6
handle 43
handle 106

for each row.

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.

Saurabh Singh TeotiaCommented:
Is their any particular reason that you want to do this with VBA??

Also have you tried..copy then paste special-->values and selecting the last option of transpose to be true which will do what you are looking for...

In additional if you still want to do go with vb route can you give me your sample file with how's the data in number of rows and how you want to see...
finnstoneAuthor Commented:
yeah many files to do it to.

here is sample data
Saurabh Singh TeotiaCommented:
Their you go..Run this will do what you are looking for..

Sub movedata()
    Dim i As Long, Z As Long

    i = 1

    Do Until i > Cells(Cells.Rows.Count, "A").End(xlUp).Row
        Z = 3
        Do Until Cells(i, Z).Value = ""
            Rows(i + 1).Insert
            Cells(i + 1, "a").Value = Cells(i, "a").Value
            Cells(i + 1, "B").Value = Cells(i, Z).Value
            Cells(i, Z).Clear
            Z = Z + 1
i = i + 1

End Sub

Open in new window


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
finnstoneAuthor Commented:
wow very cool. thanks!
Saurabh Singh TeotiaCommented:
Yw...Glad 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.