Hi!
I just started using vba.
I`ve recorded a macro, that first make a pivot, and then do a calculation on the pivot result.
I understand the problem is the hard coding, especially when adding a New sheet etc. But how can I make this work; please explain the - I Guess this has alot of crap in it, because of the recorder. I need to understand the basics.
I just started using vba.
I`ve recorded a macro, that first make a pivot, and then do a calculation on the pivot result.
I understand the problem is the hard coding, especially when adding a New sheet etc. But how can I make this work; please explain the - I Guess this has alot of crap in it, because of the recorder. I need to understand the basics.
Code:
[COLOR=#333333] Sheets.Add[/COLOR]
<code style="margin: 0px; padding: 0px; font-style: inherit;"> ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _ "Ark 1!R1C1:R10301C54", Version:=xlPivotTableVersion14).CreatePivotTable _ TableDestination:="Ark1!R3C1", TableName:="Pivottabell1", DefaultVersion _ :=xlPivotTableVersion14 Sheets("Ark1").Select Cells(3, 1).Select With ActiveSheet.PivotTables("Pivottabell1").PivotFields("K_ID") .Orientation = xlRowField .Position = 1 End With With ActiveSheet.PivotTables("Pivottabell1").PivotFields("K_NAVN") .Orientation = xlRowField .Position = 2 End With With ActiveSheet.PivotTables("Pivottabell1").PivotFields("TARIFF") .Orientation = xlRowField .Position = 3 End With ActiveSheet.PivotTables("Pivottabell1").AddDataField ActiveSheet.PivotTables( _ "Pivottabell1").PivotFields("VEKT"), "Summer av VEKT", xlSum With ActiveSheet.PivotTables("Pivottabell1").PivotFields("VERDI") .Orientation = xlRowField .Position = 4 End With ActiveSheet.PivotTables("Pivottabell1").RowAxisLayout xlTabularRow ActiveSheet.PivotTables("Pivottabell1").RepeatAllLabels xlRepeatLabels Range("F4").Select ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]" Range("F4").Select Selection.AutoFill Destination:=Range("F4:F9679") Range("F4:F9679").Select Columns("F:F").Select Selection.NumberFormat = "#,##0.00" Range("F3").Select ActiveCell.FormulaR1C1 = "Gj_snitt" Range("F9").Select </code></pre>[COLOR=#333333]End Sub[/COLOR]