ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   create pivot table from excel table (https://www.excelbanter.com/excel-worksheet-functions/60387-create-pivot-table-excel-table.html)

Pivot Table Creation Help

create pivot table from excel table
 
I have a table of quarterly shipments by vendor/product and want to convert
this to a pivot table. Right now I have 12 quaters of data, with includes 8
quaters of actual data and 4 of estimates. If I get how pivot tables work, I
would need to add 12 rows for each vendor-product combination and have one
column that includes "data." Is there an automated way to convert an excel
table, where data is in multiple columns, into a pivot table? And then update
each quarter.

Please tell me if I am going about this the wrong way. I have only used,
never set up, pivot tables,

Ellen

Bernie Deitrick

create pivot table from excel table
 
Ellen,

Select one cell in your cross-tab data table, and run the macro below. It will create a new sheet
with a database table suitable for use with pivot tables.

HTH,
Bernie
MS Excel MVP

Sub MakeTable2()
Dim myCell As Range
Dim newSheet As Worksheet
Dim mySheet As Worksheet
Dim i As Long
Dim j As Integer
Dim k As Long
Dim l As Integer
Dim mySelection As Range
Dim RowFields As Integer

Set mySheet = ActiveSheet
Set mySelection = ActiveCell.CurrentRegion
RowFields = Application.InputBox( _
"How many left-most columns to treat as row fields?", _
"CrossTab to DataBase Helper", 1, , , , , 1)
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("New Database").Delete
Application.DisplayAlerts = True
Set newSheet = Worksheets.Add
newSheet.Name = "New Database"
mySheet.Activate
i = 1
For j = mySelection(1).Row + 1 To _
mySelection(mySelection.Cells.Count).Row
For k = mySelection(1).Column + RowFields To _
mySelection(mySelection.Cells.Count).Column
If mySheet.Cells(j, k).Value < "" Then
For l = 1 To RowFields
newSheet.Cells(i, l).Value = _
Cells(j, mySelection(l).Column).Value
Next l
newSheet.Cells(i, RowFields + 1).Value = _
Cells(mySelection(1).Row, k).Value
newSheet.Cells(i, RowFields + 2).Value = _
Cells(j, k).Value
i = i + 1
End If
Next k
Next j

End Sub

"Pivot Table Creation Help" <Pivot Table Creation wrote in message
...
I have a table of quarterly shipments by vendor/product and want to convert
this to a pivot table. Right now I have 12 quaters of data, with includes 8
quaters of actual data and 4 of estimates. If I get how pivot tables work, I
would need to add 12 rows for each vendor-product combination and have one
column that includes "data." Is there an automated way to convert an excel
table, where data is in multiple columns, into a pivot table? And then update
each quarter.

Please tell me if I am going about this the wrong way. I have only used,
never set up, pivot tables,

Ellen





All times are GMT +1. The time now is 10:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com