Ich bin sehr neu zu VBA und auch zu dieser Gruppe, bitte ertragen Sie mit mir, wenn ich dumme Fragen stelle. Ich versuche, VBA-Programmier-Pivot-Tabelle zu schreiben, um zu wissen, wie viele Mitglieder für das Projekt beansprucht werden.VBA Piovot Tabelle - Auswahl mehrerer Bericht Filter
werde ich Account-ID bekommen, die in Berichtsfilter vorhanden sein wird, die von 100 der Konto-ID (von 50K Datensätze) "AI124", "AI245", "AI456", "AI671"
ein oder viele wie Konto-ID sein kann
1) Ich bin nicht fähig zu filtern mehrere Konto-IDs mit VBA.
2) Teammitglieder auf diesem Konto ID behaupteten aus dem letzten Jahr würden hatten, aber ich brauche, vom 11. März bis bevölkern, wo Wert wird in der Kopfzeile angegeben wird
ich in Internet zu überprüfen versucht und begannen unten schreiben Code, der möglicherweise nicht korrekt ist, aber als Referenz zur Verfügung stellt.
Sub CreatePivot()
' Creates a PivotTable report from the table on Sheet1
' by using the PivotTableWizard method with the PivotFields
' method to specify the fields in the PivotTable.
Dim objTable As PivotTable, objField As PivotField
' Select the sheet and first cell of the table that contains the data.
ActiveWorkbook.Sheets("DATA").Select
Range("A1").Select
' Create the PivotTable object based on the Employee data on Sheet1.
Set objTable = Sheet1.PivotTableWizard
' Specify row and column fields.
Set objField = objTable.PivotFields("Emp Last Name")
objField.Orientation = xlRowField
objField.Position = 1
Set objField = objTable.PivotFields("Emp Ser Num")
objField.Orientation = xlRowField
objField.Position = 2
Set objField = objTable.PivotFields("Week Ending Date")
objField.Orientation = xlColumnField
objField.Position = 1
' Specify a data field with its summary
' function and format.
Set objField = objTable.PivotFields("Total Hrs Expended")
objField.Orientation = xlDataField
objField.Function = xlSum
objField.NumberFormat = "#,##0"
' Specify a page field.
Set objField = objTable.PivotFields("Account Id")
objField.Orientation = xlPageField
Application.ScreenUpdating = False
'ActiveSheet.PivotTables("PivotTable2").ManualUpdate = True
objTable.ManualUpdate = True
'objTable.PivotFields("Account Id").ClearAllFilters
' objTable.PivotFields("Account Id").CurrentPage = Array("PJ1234", _ "AI82159", "AI5444")
'-------------
Set objField = objTable.PivotFields("Account Id")
objField.Orientation = xlPageField
Myarray = Array("PJ1234", "AI5444", "AI82159")
For x = 1 To objField.PivotFields.Count
objField.PivotFields(x).Visible = False
Next
For x = 0 To 3
objField.PivotFields(Myarray(x)).Visible = True
Next
objTable.ManualUpdate = False
Application.ScreenUpdating = True
' Preview the new PivotTable report.
ActiveSheet.PrintPreview
' Prompt the user whether to delete the PivotTable.
Application.DisplayAlerts = False
If MsgBox("Delete the PivotTable?", vbYesNo) = vbYes Then
ActiveSheet.Delete
End If
Application.DisplayAlerts = True
End Sub
Ihre Hilfe wird sehr geschätzt.
Willkommen zu SO. Sie haben nicht wirklich eine Frage gestellt. Hast du deinen Code ausprobiert? Hat es Fehler verursacht? Was haben Sie erwartet und welche Teile haben nicht wie erwartet funktioniert? – OldUgly
Bitte poste ein [MCVE] –
Hallo OldUgly, Danke. Meine Frage ist, wie man VBA-Programm schreibt, um mehrere Konto-IDs als Teil des Berichtsfilters auszuwählen? fügte auch meinen Code als Referenz hinzu. Danke im Voraus. Auch gab es keinen Fehler und als ich versuchte, in Myarray einzuschließen, bekomme ich nur erste Konto-Nr. Details, die nicht für mehrfache Konto Identifikation erhalten –