Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
948to952
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
948to952
948to952
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Pivot, Makro Feldnamen - woher kommt das Feld

Pivot, Makro Feldnamen - woher kommt das Feld
11.02.2008 09:18:10
Lutz
Hallo Excel Spezialisten,
ich habe diverse Pivottabellen geerbt die aus Access-Tabellen erstellt werden. Die Feldnamen sind auch oft geändert.
Habe mal dieses Makro gefunden bzw. von Luschi bekommen:

Sub pivotFeldnamen()
Dim pT As PivotTable
Dim pF As PivotField
Dim s As String
s = "aktueller Name" & vbTab & "Originalname" & vbCrLf
Set pT = ActiveSheet.PivotTables("PivotTable1")
'Abfragetext, auf der die Pivottabelle beruht
' MsgBox pT.PivotCache.CommandText
For Each pF In pT.PivotFields
s = s & pF.Caption & vbTab & vbTab & pF.SourceName & vbCrLf
Next pF
Set pF = Nothing
Set pT = Nothing
MsgBox s
End Sub


2 Fragen:
Ich bräuchte das als Makro der alle Pivottabellen in dem aktuellen Sheet abfragt
Mir wäre ein neues Blatt als Ausgabe lieber als die Dialogbox die oft schlecht zu lesen ist
Und eine Zusatzfragestellung:
Ich habe in einer Pivottabelle 3 Felder von denen ich nicht weiß wo die herkommen:
Das obige Makro bricht ab wenn ich es über die Tabelle laufen lasse - warum?
Die Spalten und Werte sind in der Basis-Access-Tabelle nicht zu finden und ich finde auch kein berechnetes Feld. Also: wie können diese Felder/Spalten in die Pivottabelle kommen? Ich habe auch schon in MS Query nachgesehen und nichts gefunden.
Vielen Dank für Eure Hilfe
Gruß Lutz

9
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Pivot, Makro Feldnamen - woher kommt das Feld
11.02.2008 10:30:03
Renee
Hi Lutz,
Probier's mal damit (Code gehört in ein Modul):

Sub PivotSourceDataAuslesen()
Dim pvt As PivotTable
Dim pfd As PivotField
Dim wsh As Worksheet
Dim SheetExists As Boolean
Dim ix As Integer
Dim pvtCount As Integer
pvtCount = 0
SheetExists = True
For Each wsh In ActiveWorkbook.Worksheets
If wsh.Name = "PivotSource" Then
SheetExists = False
Exit For
End If
Next
If SheetExists Then
ActiveWorkbook.Sheets.Add Before:=ActiveWorkbook.Worksheets(1)
ActiveSheet.Name = "PivotSource"
End If
Sheets("PivotSource").Cells(1, 1).Value = "Tabelle"
Sheets("PivotSource").Cells(1, 2).Value = "PivotName"
Sheets("PivotSource").Cells(1, 3).Value = "Eigenschaften"
Sheets("PivotSource").Cells(1, 4).Value = "Felder"
For Each wsh In ActiveWorkbook.Worksheets
For Each pvt In wsh.PivotTables
pvtCount = pvtCount + 1
Sheets("PivotSource").Cells(1 + pvtCount, 1) = wsh.Name
Sheets("PivotSource").Cells(1 + pvtCount, 2) = pvt.Name
For ix = 1 To 4
Sheets("PivotSource").Cells(1 + pvtCount, 3) = "Nummer:"
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3) = "Titel:"
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3) = "FeldName:"
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3) = "QuellenName:"
Next ix
ix = 0
For Each pfd In pvt.DataFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = ix
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3 + ix) = pfd.SourceName
Next
pvtCount = pvtCount + 3
Next
Next
If pvtCount = 0 Then
MsgBox "Keine Pivottabellen in dieser Arbeitsmappe", vbExclamation
Application.DisplayAlerts = False
Sheets("PivotSource").Delete
Application.DisplayAlerts = True
Else
MsgBox "Total " & pvtCount / 4 & " Pivottabellen in der Arbeitsmappe.", vbInformation
End If
End Sub


GreetZ Renée

Anzeige
AW: Pivot, Makro Feldnamen - woher kommt das Feld
11.02.2008 11:08:00
Lutz
Hallo Renee,
starkes Makro, fast genau das was ich brauche.
In der Liste tauchen aber nur die Auswertungsfelder auf (Summe von Menge, Summe von Betrag), aber nicht die gesamten Felder (z.B. nach denen Gruppiert wird ...).
Geht das auch noch? Dann wäre es wirklich optimal.
Gruß Lutz

AW: Pivot, Makro Feldnamen - woher kommt das Feld
11.02.2008 11:20:00
Renee
Hi Lutz,
Ausgebaut mit Rows/Columns, wobei D=Datenfelder, Z=Zeilenfelder, S=Spaltenfelder:

Sub PivotSourceDataAuslesen()
Dim pvt As PivotTable
Dim pfd As PivotField
Dim wsh As Worksheet
Dim SheetExists As Boolean
Dim ix As Integer
Dim ixC As Integer
Dim pvtCount As Integer
pvtCount = 0
SheetExists = True
For Each wsh In ActiveWorkbook.Worksheets
If wsh.Name = "PivotSource" Then
SheetExists = False
Exit For
End If
Next
If SheetExists Then
ActiveWorkbook.Sheets.Add Before:=ActiveWorkbook.Worksheets(1)
ActiveSheet.Name = "PivotSource"
End If
Sheets("PivotSource").Cells(1, 1).Value = "Tabelle"
Sheets("PivotSource").Cells(1, 2).Value = "PivotName"
Sheets("PivotSource").Cells(1, 3).Value = "Eigenschaften"
Sheets("PivotSource").Cells(1, 4).Value = "[D]aten,[S]palten,[Z]eilen-Felder"
For Each wsh In ActiveWorkbook.Worksheets
For Each pvt In wsh.PivotTables
pvtCount = pvtCount + 1
Sheets("PivotSource").Cells(1 + pvtCount, 1) = wsh.Name
Sheets("PivotSource").Cells(1 + pvtCount, 2) = pvt.Name
For ix = 1 To 4
Sheets("PivotSource").Cells(1 + pvtCount, 3) = "Nummer:"
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3) = "Titel:"
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3) = "FeldName:"
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3) = "QuellenName:"
Next ix
ix = 0
For Each pfd In pvt.DataFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "D:" & ix
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3 + ix) = pfd.SourceName
Next
For Each pfd In pvt.ColumnFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "S:" & ix
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Next
For Each pfd In pvt.RowFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "Z:" & ix
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Next
pvtCount = pvtCount + 3
Next
Next
If pvtCount = 0 Then
MsgBox "Keine Pivottabellen in dieser Arbeitsmappe", vbExclamation
Application.DisplayAlerts = False
Sheets("PivotSource").Delete
Application.DisplayAlerts = True
Else
MsgBox "Total " & pvtCount / 4 & " Pivottabellen in der Arbeitsmappe.", vbInformation
End If
End Sub


GreetZ Renée

Anzeige
Kosmetik-Korrektur
11.02.2008 11:44:59
Renee
Hi Lutz,
Hab zwar einen neue Variable (ixC) eingeführt. Hier wird sie auch gebraucht, um die Spalten- bzw. Zeilen-Felder richtig zu nummerieren.

Sub PivotSourceDataAuslesen()
Dim pvt As PivotTable
Dim pfd As PivotField
Dim wsh As Worksheet
Dim SheetExists As Boolean
Dim ix As Integer
Dim ixC As Integer
Dim pvtCount As Integer
pvtCount = 0
SheetExists = True
For Each wsh In ActiveWorkbook.Worksheets
If wsh.Name = "PivotSource" Then
SheetExists = False
Exit For
End If
Next
If SheetExists Then
ActiveWorkbook.Sheets.Add Before:=ActiveWorkbook.Worksheets(1)
ActiveSheet.Name = "PivotSource"
End If
Sheets("PivotSource").Cells(1, 1).Value = "Tabelle"
Sheets("PivotSource").Cells(1, 2).Value = "PivotName"
Sheets("PivotSource").Cells(1, 3).Value = "Eigenschaften"
Sheets("PivotSource").Cells(1, 4).Value = "[D]aten,[S]palten,[Z]eilen-Felder"
For Each wsh In ActiveWorkbook.Worksheets
For Each pvt In wsh.PivotTables
pvtCount = pvtCount + 1
Sheets("PivotSource").Cells(1 + pvtCount, 1) = wsh.Name
Sheets("PivotSource").Cells(1 + pvtCount, 2) = pvt.Name
For ix = 1 To 4
Sheets("PivotSource").Cells(1 + pvtCount, 3) = "Nummer:"
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3) = "Titel:"
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3) = "FeldName:"
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3) = "QuellenName:"
Next ix
ix = 0
For Each pfd In pvt.DataFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "D:" & ix
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3 + ix) = pfd.SourceName
Next
ixC = ix
For Each pfd In pvt.ColumnFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "S:" & ix - ixC
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Next
ixC = ix
For Each pfd In pvt.RowFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "Z:" & ix - ixC
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
Next
pvtCount = pvtCount + 3
Next
Next
If pvtCount = 0 Then
MsgBox "Keine Pivottabellen in dieser Arbeitsmappe", vbExclamation
Application.DisplayAlerts = False
Sheets("PivotSource").Delete
Application.DisplayAlerts = True
Else
MsgBox "Total " & pvtCount / 4 & " Pivottabellen in der Arbeitsmappe.", vbInformation
End If
End Sub


GreetZ Renée

Anzeige
AW: Kosmetik-Korrektur
11.02.2008 12:01:18
Lutz
Hallo Renee,
99% - wirklich beeindruckend.
Das einzige was noch fehlt sind die Quellennamen bei den S+Z Werten:
Germany PivotTable1 Nummer: D:1 D:2 S:1 S:2 Z:1 Z:2 Z:3
Titel: MengeSI1-test NetAmnt F15 Data SG SSG3_2 SMG3-Test
FeldName: MengeSI1-test NetAmnt F15 Data SG SSG3_2 SMG3-Test
QuellenName: MengeSI NettoBetragSI
Wenn ich das habe bin ich (wahrscheinlich glücklich) - die Felder: SG SSG3_2 SMG3-Test, finde ich nähmlich nirgendwo, weder in den berechneten Feldern, noch in der Access-Datenbank die der Pivottabelle zugrundeliegt. Bin gespannt was da drinsteht.
Vielen Dank schon mal Gruß Lutz

Anzeige
AW: Kosmetik-Korrektur
11.02.2008 12:53:05
Renee
Hi Lutz,
Ersetze diese Codeteile:

For Each pfd In pvt.ColumnFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "S:" & ix - ixC
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
On Error Resume Next
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3 + ix) = pfd.SourceName
On Error GoTo 0
Next
ixC = ix
For Each pfd In pvt.RowFields
ix = ix + 1
Sheets("PivotSource").Cells(1 + pvtCount, 3 + ix) = "Z:" & ix - ixC
Sheets("PivotSource").Cells(1 + pvtCount + 1, 3 + ix) = pfd.Caption
Sheets("PivotSource").Cells(1 + pvtCount + 2, 3 + ix) = pfd.Name
On Error Resume Next
Sheets("PivotSource").Cells(1 + pvtCount + 3, 3 + ix) = pfd.SourceName
On Error GoTo 0
Next


GreetZ Renée

Anzeige
AW: Kosmetik-Korrektur
11.02.2008 14:05:49
Lutz
Hallo Renee,
Dein Code ist perfekt. Er zeigt alles an.
Ich bekomme auch die Felder die ich gesucht habe.
Ein Problem bleibt aber bestehen: woher kommen die Felder SSG3 und SMG3? Wenn ich einen doppelclick auf die Summe der Pivottabelle mache zeigt er mir ja alle Einzelsätze an: aber keine Spalte mit diesem Namen! Ich finde auch in der Query nichts und bei berechneten Felder.
Woher sonst kann ein Feld in einer Pivottabelle kommen?
Gruß und tausend Dank Lutz

Das kann ich dir leider auch nicht...
11.02.2008 14:41:00
Renee
sagen, da ich weder Einblick in deine DB noch in deine Query oder Pivotdaten habe.
Vielleicht kannst Du die Arbeitsmappe hochladen ?
GreetZ Renée

Anzeige
AW: Das kann ich dir leider auch nicht...
11.02.2008 15:40:56
lobby007
Hallo Renee,
vielen Dank für die Hilfe und das Angebot. Ich hoffe Du bist morgen noch mal im Forum, ich mußte heute eher weg von der Arbeit. In der Datei sind sensible Firmendaten - werde morgen man die Preis etc. auf 0 setzen und die Datei hochladen.
Ich wünsche Dir noch einen schönen Tag.
Gruß Lutz

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige