PDA

View Full Version : Convert data for Pivot Table

teeitup
05-27-2008, 09:10 AM
I currently have a set of data in a traditional budget layout.

With columns:

Primary, Group, Sub-Group, and dates: Jan Feb March Etc. (each in its own column)

Listed under Primary, Group and Sub-Group is information about the type of expense.

Listed under each month is the amount for the given month.

So each row contains many different months of data located in many columns

What I would like to do is convert the data so it can more effectively used in a pivot table.

With Columns:

Primary, Group, Sub-Group, Month, Amount

In this layout instead of having months in many columns it would simply list the month in one common column. So each row would contain only one amount.

I've racked my brain, but can't think of an easy way to make this conversion.

Thanks for the help,

Doug

xld
05-27-2008, 10:10 AM
Public Sub ProcessData()
Dim i As Long, j As Long
Dim LastRow As Long

With Application

.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Columns("D:E").Insert
.Range("D1:E1").Value = Array("Month", "Amount")
For i = LastRow To 2 Step -1

.Rows(i + 1).Resize(11).Insert
For j = 17 To 6 Step -1

.Cells(i + j - 6, "D").Value = .Cells(1, j).Value
.Cells(i + j - 6, "E").Value = .Cells(i, j).Value
Next j
.Cells(i, "A").Resize(, 3).Copy .Cells(i + 1, "A").Resize(11)
Next i

.Columns("F:Q").Delete
End With

With Application

.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With

End Sub

teeitup
05-27-2008, 11:48 AM
XLD,

Thanks for your help! The macro works great, except I've more then one year worth of columns is there anyway the macro could include more then 1 year?