Mefisto...diabeł czy anioł?

Cze¶æ,

jestem totalnym laikiem i dopiero uczê siê tworzenia makr. Nie znam Virtual Basic, wiêc po prostu nagrywam makra. Chcia³em zrobiæ makro, które sumuje mi warto¶ci z dwóch kolumn. Chodzi mi o ca³y arkusz, poniewa¿ ilo¶æ linii w ró¿nych raportach mo¿e siê ró¿niæ (kolumny zawsze takie same). Przy tworzeniu tego makra, pojawia mi siê komunikat:

Run-time error '1004'
Unable to get the PivotFields property of the Pivot Table class
(linia w poni¿szym kodzie zaznaczona na czerwono)


Sub Daily_Orders_Macro()
'
' Daily_Orders_Macro Macro
' Macro recorded 12/03/2009 by eryk
'

'
    Cells.Select
    Cells.EntireColumn.AutoFit
    Rows("1:1").Select
    Selection.Delete Shift:=xlUp
    Columns("B:C").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:D").Select
    Selection.Delete Shift:=xlToLeft
    Rows("1:1").Select
    With Selection
        .WrapText = False
        .Orientation = 90
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Font.Bold = True
    Cells.Select
    Cells.EntireColumn.AutoFit
    Cells.Select
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!C1:C14").CreatePivotTable TableDestination:="", TableName:= _
        "PivotTable1", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    [b][color=red]With ActiveSheet.PivotTables("PivotTable1").PivotFields("Article Name")[/color][/b]       
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Article No")
        .Orientation = xlRowField
        .Position = 2
    End With
    Range("A6").Select
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Article Name").Subtotals = _
        Array(False, False, False, False, False, False, False, False, False, False, False, False)
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Ordered Value"), "Count of Ordered Value", xlCount
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Ordered Qty"), "Count of Ordered Qty", xlCount
    ActiveSheet.PivotTables("PivotTable1").PivotSelect "'Count of Ordered Value'", _
        xlDataAndLabel, True
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of Ordered Value"). _
        Function = xlSum
    ActiveSheet.PivotTables("PivotTable1").PivotSelect "'Count of Ordered Qty'", _
        xlDataAndLabel, True
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of Ordered Qty"). _
        Function = xlSum
    Range("C3").Select
    With ActiveSheet.PivotTables("PivotTable1").DataPivotField
        .Orientation = xlColumnField
        .Position = 1
    End With
    Range("C5").Select
    ActiveWindow.FreezePanes = True
End Sub


Wcze¶niej zrobi³em du¿o bardziej skomplikowane makro (przynajmniej dla mnie :)), postêpowa³em tak samo (zaznaczaj±c wszystkie komórki w arkuszu i dzia³a³o. Wiecie co mo¿e byæ przyczyn± wyst±pienia tego b³êdu??

Z góry dziêkujê za odpowied¼,
pozdr Eryk
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • katkaras.opx.pl