Makro som skapar pivottabell

Loranga

New Member
Joined
Jan 30, 2007
Messages
36
Aloha,

Jag försöker skapa ett makro som skapar en pivottabell. Jag vet att makroinspelaren inte är helt ultimat, särskilt när det gäller piottabeller men jag provade ändå för att försöka få någon att börja med. Tyvärr stötte jag på problem direkt, nämligen: "Körfel 1004: Program elle objekdefinierat fel."

<code> ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"'Test'!R1C1:R5755C15").CreatePivotTable TableDestination:="", _
TableName:="Pivottabell1", DefaultVersion:=xlPivotTableVersion10</code>
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hej!

Jag vet ju inte riktigt hur du vill att det skall se ut och hur din data är o.s.v men om du gör ett enkelt exempel till att börja med kanske du kan anpassa?

Skriv in lite data i kolumn A till C med rubrikerna "Lag", "Spelare" och "Mål" på första raden och kör sedan:

Code:
Sub xxx()
 
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "A:C").CreatePivotTable TableDestination:=Range("E1"), TableName _
        :="PivotTable1"
 
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Range("B1"), _
        ColumnFields:=Range("A1")
 
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Mål")
         .Orientation = xlDataField
         .Function = xlSum
    End With
 
End Sub
 
Upvote 0
Tusen tack för hjälpen, det var precis vad jag behövde för att komma igång. Nu funkar det som det ska.
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top