Convert columnar data table to row data

I have an excel budget table with account numbers as rows and period dates as columns.  I want to convert the table so that there are 12 rows for each of the 1100 account numbers.  Column A would be the Account Number, Column B the Period Ending Date and Column C the budgeted value for that account and period.  If the period value is blank, the value would be zero.

Is there an easy way to do this via VBA?

Thanks

Glen
GPSPOWAsked:
Who is Participating?
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:
Can you post your sample file to have a look...with what you are trying to do...

Saurabh...
0
GPSPOWAuthor Commented:
Attached is snippet of the budget format.

Each account number should have 12 rows of data.  One for each month.

thanks

glen
Budget.xlsx
0
Saurabh Singh TeotiaCommented:
Glen,

Quick question if the period value is blank or zero? You still want to see that entry with combination of the account or you don't want to see that??

Saurabh...
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

GPSPOWAuthor Commented:
If the value is blank or zero, use zero.

Thanks

Glen
0
Saurabh Singh TeotiaCommented:
Okay here is the macro code along with your file where it creates a sheet with the name of output with the desired results of what you are looking for...

Sub output()
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim ws1 As Worksheet
    Dim lrow As Long, cell As Range, rng As Range
    Dim k As Long, lr As Long

    On Error Resume Next
    Sheets("Output").Delete
    Sheets.Add after:=Sheets(Sheets.Count)
    ActiveSheet.Name = "Output"
    Set ws1 = ActiveSheet
    Set ws = Sheets("Sheet1")

    ws1.Range("A1").Value = "Account"
    ws1.Range("b1").Value = "date"
    ws1.Range("C1").Value = "Amount"

    lrow = ws.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    Set rng = ws.Range("A2:A" & lrow)

    For Each cell In rng
        k = 2
        Do Until k > 13
            lr = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
            ws1.Range("A" & lr).Value = cell.Value
            ws1.Range("B" & lr).Value = ws.Cells(1, k).Value
            ws1.Range("C" & lr).Value = ws.Cells(cell.Row, k).Value
            k = k + 1
        Loop

    Next cell

    ws1.Cells.EntireColumn.AutoFit

    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

End Sub

Open in new window


Saurabh...
Budget.xlsm
0

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
GPSPOWAuthor Commented:
Thank you
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.