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?


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

GPSPOWAuthor Commented:
Attached is snippet of the budget format.

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


Saurabh Singh TeotiaCommented:

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??

Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

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


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.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

    Next cell


    Application.DisplayAlerts = True
    Application.ScreenUpdating = True

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