VBA-Vorschlag
23.04.2014 12:48:09
Klaus
Hi Basti,
lösch mal in deiner Musterdatei alles ab Zeile 17 nach unten und lass dann folgendes Makro laufen:
Sub ErstelleTagesPlaene()
'Variablen nach gusto ändern und anpassen
Const BlattDaten As String = "Blatt1"
Const SpalteAb As Long = 5
Const ZeileDatum As Long = 1
Const ZeileVon As Long = 2
Const SpaltePK As Long = 1
Const SpalteIdent As Long = 2
Const SpalteAnzahl As Long = 3
Const SpalteDLZ As Long = 4
Const SpalteDatumNeu As Long = 1
Const SpaltePKneu As Long = 1
Const SpalteIdentNeu As Long = 2
Const SpalteAnzahlNeu As Long = 3
Dim SpalteBis As Long
Dim ZeileBis As Long
Dim wksNeu As Worksheet
Dim s As Long 'Spaltenindex
Dim z As Long 'Zeilenindex
Dim s2 As Long 'Spalte Auswertung
Dim z2 As Long 'Zeile Auswertung
'Neues Blatt für die Auswertung einfügen
Sheets.Add
Set wksNeu = ActiveSheet
z2 = 1
With Sheets(BlattDaten)
.Activate
SpalteBis = .Cells(ZeileDatum, .Columns.Count).End(xlToLeft).Column
ZeileBis = .Cells(.Rows.Count, SpaltePK).End(xlUp).Row
For s = SpalteAb To SpalteBis
'Datum und Überschriften eintragen
wksNeu.Cells(z2, SpalteDatumNeu).Value = .Cells(ZeileDatum, s).Value
wksNeu.Cells(z2, SpalteDatumNeu).NumberFormat = "m/d/yyyy"
z2 = z2 + 1
wksNeu.Cells(z2, SpaltePKneu).Value = "PK"
wksNeu.Cells(z2, SpalteIdentNeu).Value = "Ident-Nr."
wksNeu.Cells(z2, SpalteAnzahlNeu).Value = "Anzahl anteilig"
z2 = z2 + 1
For z = ZeileVon To ZeileBis
If Not .Cells(z, s).Value = "" Then
'Werte übertragen
wksNeu.Cells(z2, SpaltePKneu).Value = .Cells(z, SpaltePK).Value
wksNeu.Cells(z2, SpalteIdentNeu).Value = .Cells(z, SpalteIdent).Value
wksNeu.Cells(z2, SpalteAnzahlNeu).Value = VBA.Round(.Cells(z, s).Value / .Cells( _
z, SpalteDLZ).Value * .Cells(z, SpalteAnzahl).Value, 0)
z2 = z2 + 1
End If
Next z
z2 = z2 + 1
Next s
End With
wksNeu.Cells.EntireColumn.AutoFit
End Sub
Anmerkung: Dein Muster ist falsch. Am 24.04. fehlt dir der Rest von Ident 220716, nochmal 508 Stück!
Die Rundung auf 0 Stellen hast du in der Formel vorgegeben, das habe ich übernommen. Für Rundungsfehler haftest du selber!
Da du weder Level noch Version angegeben hast, habe ich mich entschlossen die Zellformatierung (farbige Hintergründe der Zellen, genau genommen) zu ignorieren.
Grüße,
Klaus M.vdT.