Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
488to492
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
488to492
488to492
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Trennung von Quartalen

Trennung von Quartalen
27.09.2004 09:29:54
Quartalen
Hallo! Ich würde gerne einen Macro machen der in der Tabelle "excel" (ist mit Daten gefüllt bis einschließlich Spalte L) schaut welches Jahr das Datum in der Spalte "I" hat und dann bei dem zu untersuchenden Jahr (z.B. diese Jahr oder letztes Jahr) die Daten in Quartale einteilz und in extra dafür erstellte Worksheets verschiebt. Also z.B. Ich will dieses Jahr untersuchen. dann erstllt der Macro 4 Worksheets und kopiert von der Tabelle "excel" erstaml alle Daten vom 1 Quartal in der Zeile "I" in die Tabelle "1.Quartal" usw. bis die Daten eines Jahres verteilt sind. Schön wäre es auch wenn man eine Abfrage einrichten könnte´die dann schaut z.B. wir haben heute den 3 Quartal d.h man braucht den 4 Quartal sich sparen. Das wäre zwar schön, aber kein muss Hauptsache es läuft :).
Ich habe da schon was vorbereitet ;) aber bisher kopiert es keine Zeilen. Ich bin dankbar für jeden Tip

Private Sub But_dieser_Jahr_Quartal_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim dtDatum As Date
Dim dtMonat As Integer
Dim dtJahr As Integer
dtJahr = 2004
dtMonat = 10
Dim Ws As Worksheet, Ws1 As Worksheet
Dim Mt(), i&
On Error Resume Next
Mt = Array("1.Quartal", "2. Quartal", "3.Quartal", "4. Quartal")
' Sheets herstellen
For i = 0 To UBound(Mt)
Set Ws = Worksheets(Mt(i))
If Err.Number <> 0 Then _
Set Ws = Sheets.Add(After:=Worksheets(Worksheets.Count)): Ws.Name = Mt(i)
Err.Clear
Next i
Set Ws = Worksheets(TBL)
If Err.Number <> 0 Then _
MsgBox "Blatt " & TBL & " nicht gefunden .. ", vbCritical: Exit Sub
' Einsortieren
With Ws
For i = 1 To .Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row
' handelt es sich überhaupt um ein Datum ?
If IsDate(.Cells(i, Range(STARTZELLE).Column).Value) Then
'kopieren der Daten auf das entsprechende Monatsblatt
' ( Zeile ins Monatsblatt )
'Und jetzt kommt die Jahresabfrage
If Month(dtDatum) <> dtMonat And Month(dtDatum) <> dtMonat + 1 And Month(dtDatum) <> dtMonat + 2 And Format(Year(dtDatum), "yyyy") <> dtJahr Then
Set Ws1 = Worksheets(Mt(Month(.Cells(i, Range(STARTZELLE).Column).Value) - 1))
' kopieren der Zeile in das entsprechende Blatt in die erste freie Zeile
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws1.Cells(Ws1.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
' loeschen der Zeile
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
End If
Next i
End With
Set Ws = Nothing: Erase Mt: Set Ws1 = Nothing
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Trennung von Quartalen
27.09.2004 09:40:31
Quartalen
Hallo Ryu_Hoshi,
wenn du deine Daten als Datenbank organisierst,
bietet sich der Einsatz von Pivottabellen an.
Damit kannst du standardmäßig nach Monaten,
Quartalen + Jahren auswerten.
Freundliche Grüße
Rolf Beißner
AW: Trennung von Quartalen
Quartalen
Hallo Rolf!
Danke für den Tip mit Pivottabellen, aber würde es gerne ohne Pivot machen, aber Danke trotzdem!
AW: Trennung von Quartalen
Quartalen
Hallo Leute! Ich bin auf dem gutem Wege das Problem selber zu lösen. Den 1 Quartal habe ich schon :) Sobald ich fertig bin poste ich die Lösung mal.
Gelöst!
Ryu_HOshi

Private Sub But_dieser_Jahr_Quartal_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim Ws As Worksheet, Ws1 As Worksheet, Ws2 As Worksheet, Ws3 As Worksheet, Ws4 As Worksheet, Ws5 As Worksheet
Dim Mt(), i&
On Error Resume Next
Mt = Array("1.Quartal", "2.Quartal", "3.Quartal", "4.Quartal")
' Sheets herstellen
For i = 0 To UBound(Mt)
Set Ws = Worksheets(Mt(i))
If Err.Number <> 0 Then _
Set Ws = Sheets.Add(After:=Worksheets(Worksheets.Count)): Ws.Name = Mt(i)
Ws.Visible = xlSheetHidden
Err.Clear
Next i
Set Ws = Worksheets(TBL)
Set Ws2 = ThisWorkbook.Worksheets("1.Quartal")
Set Ws3 = ThisWorkbook.Worksheets("2.Quartal")
Set Ws4 = ThisWorkbook.Worksheets("3.Quartal")
Set Ws5 = ThisWorkbook.Worksheets("4.Quartal")
If Err.Number <> 0 Then _
MsgBox "Blatt " & TBL & " nicht gefunden .. ", vbCritical: Exit Sub
' Einsortieren
With Ws
For i = 1 To .Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row
' handelt es sich überhaupt um ein Datum ?
If IsDate(.Cells(i, Range(STARTZELLE).Column).Value) Then
'1 Quartal
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 1 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws2.Cells(Ws2.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 2 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws2.Cells(Ws2.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 3 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws2.Cells(Ws2.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
'2 Quartal
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 4 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws3.Cells(Ws3.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 5 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws3.Cells(Ws3.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 6 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws3.Cells(Ws3.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 7 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws4.Cells(Ws4.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 8 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws4.Cells(Ws4.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 9 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws4.Cells(Ws4.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 10 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws5.Cells(Ws5.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 11 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws5.Cells(Ws5.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
If Year(.Cells(i, Range(STARTZELLE).Column).Value) = Year(Date) And Month(.Cells(i, Range(STARTZELLE).Column).Value) = 12 Then
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).Copy Destination:= _
Ws5.Cells(Ws5.Cells(Rows.Count, Range(STARTZELLE).Column).End(xlUp).Row + 1, 1)
.Range(.Cells(i, 1), .Cells(i, LAST_COL)).ClearContents
End If
End If
Next i
End With
Set Ws = Nothing: Erase Mt: Set Ws1 = Nothing: Set Ws2 = Nothing: Set Ws3 = Nothing: Set Ws4 = Nothing: Set Ws5 = Nothing
Application.ScreenUpdating = True
Module1.dieser_Jahr_Quartal
End Sub

Anzeige
AW: Gelöst!
28.09.2004 09:16:06
Rolf
Hallo Ryu_HOshi,
herzlichen Glückwunsch zu deiner Lösung.
Allerdings dürfte es ziemlich aufwändig sein,
diese Lösung bei ähnlichen Gegebenheiten jedesmal anzupassen.
Ich persönlich ziehe deshalb den Einsatz der doch ziemlich
komfortablen Standardfunktionen "Pivot- bzw. Teilergebnis" vor.
Herzliche Grüße
Rolf
AW: Gelöst!
Ryu_Hoshi
Hallo Ralf!
Danke für deine Glückwünsche! Ich weiss meine Lösung ist nicht grad die beste. Bei mir ist Macro noch eine Menge was man verbessern kann. Aber ich bin froh dass alle Analysen laufen und das ist das wichtigste. Jetzt kann ich es auch noch verbessern. Aber in der Zeit wo ich das ganze Macro erstellt habe, ahbe ich durch die HIlfe von anderens ehr viel gelernt. Ich habe ja erst vor 2 MOnaten mit vba angefangen.
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige