Hi Tom
Yes the code is written in VBA
I suspect that line wrap in your Newsreader is causing the problem.
I have reproduced the code below, with more forced line breaks so hopefully
your newsreader won't mess it up.
Sub CreatePivot()
Dim wss As Worksheet, wsd As Worksheet
Dim i As Long, j As Long, fname As String
Set wss = Sheets("Sheet1")
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=wss.Range("A1:CZ20000")) _
.CreatePivotTable TableDestination:="", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
Set wsd = ActiveSheet
wsd.PivotTableWizard TableDestination:=wsd.Cells(3, 1)
wsd.Cells(3, 1).Select
' in this case the first 2 columns of source data have been added to
' Row field and Page field respectively
wsd.PivotTables("PivotTable1") _
.AddFields RowFields:=Array("Date", _
"Data"), PageFields:="Name"
j = 2 ' set the start column as 1 less than where you wish to pick
' up data fields from
For i = 1 To 60
' loop for 60 columns to add fields to the data area
' picking up the field name from the column header
fname = wss.Cells(1, j + i).Value
With wsd.PivotTables("PivotTable1").PivotFields(fname)
.Orientation = xlDataField
.Function = xlSum ' force a Sum
' get rid of Sum of before field name
' by adding a space to the source field Name
.Name = fname & " "
.Position = i
End With
Next
' next part allocates the 60 data fields across columns instead
' of appearing under each other (if that is what is required)
With ActiveSheet.PivotTables("PivotTable1").DataPivotField
.Orientation = xlColumnField
.Position = 1
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
--
Regards
Roger Govier
tlee said:
Is the code VBA?
It does not seem to compile in VBA. The := outside the scope of a
paramter appears to fail
e.g. using TableDestination:="" as an assignment.
Sorry is this is a silly question. Tom
__________ Information from ESET Smart Security, version of virus
signature database 4821 (20100130) __________
The message was checked by ESET Smart Security.
http://www.eset.com
__________ Information from ESET Smart Security, version of virus signature database 4821 (20100130) __________
The message was checked by ESET Smart Security.
http://www.eset.com