Supportnet / Forum / Tabellenkalkulation
Summenrechnung mit Makro
Frage
Hallo ich möchte folgendes machen...
Ich habe in der Zeile A diverse Produktkategorien. Zb
AA01 100 euro
AA01 200 Euro
AA01 200 Euro
BB01 100 euro
BB01 100 euro
CC01 245 Euro
Da es im Monat dadrauf zum Beispiel auch so Aussehn kann
AA01 150 Euro
BB01 100 Euro
BB01 300 Euro
BB04 240 Euro
CC01 30 Euro
CC01 270 Euro
Brauche ich einen Makro Baustein der unter jeder Kategorie eine neue Zeile öffnet und die jeweilige Summe ausgibt also so:
AA01 100 Euro
AA01 200 Euro
AA01 100 euro
Summe AA01 400 euro
BB01 200 Euro
BB01 240 Euro
Summe BB01 440 euro
...
Wie kann ich das nun machen ? ICh hab an eine IF Funktion gedacht aber weiss nicht wie ich das umsetzten soll ( da die neue Zeile mit dem Summen ergebnis ja jedesmal wenn ich das Makro drüberlaufen lasse an eine andere Stelle rutschen wird wahrscheinlich )
Danke im Vorraus
Yannick
Antwort 1 von nighty
hi all :)
eine atwas andere variante :)
gruss nighty
Option Explicit
Sub makro01()
Dim zeile As Long
Dim merker As Long
Range("A1:A65535").ClearComments
On Error GoTo fehler
For zeile = 2 To Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
merker = merker + Cells(zeile, 2)
If Mid(Cells(zeile, 1), 1, 1) <> Mid(Cells(zeile + 1, 1), 1, 1) Then
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Text Text:="" & merker
Cells(zeile, 1).Comment.Visible = False
merker = 0
End If
Next zeile
End
fehler:
If Err = 1004 Then
Cells(zeile, 1).ClearComments
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Visible = False
Resume Next
End If
End Sub
eine atwas andere variante :)
gruss nighty
Option Explicit
Sub makro01()
Dim zeile As Long
Dim merker As Long
Range("A1:A65535").ClearComments
On Error GoTo fehler
For zeile = 2 To Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
merker = merker + Cells(zeile, 2)
If Mid(Cells(zeile, 1), 1, 1) <> Mid(Cells(zeile + 1, 1), 1, 1) Then
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Text Text:="" & merker
Cells(zeile, 1).Comment.Visible = False
merker = 0
End If
Next zeile
End
fehler:
If Err = 1004 Then
Cells(zeile, 1).ClearComments
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Visible = False
Resume Next
End If
End Sub
Antwort 2 von nighty
hi all :)
ups korrigiert :))
gruss nighty
Option Explicit
Sub makro01()
Dim zeile As Long
Dim merker As Long
Range("A1:A65535").ClearComments
For zeile = 2 To Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
merker = merker + Cells(zeile, 2)
If Mid(Cells(zeile, 1), 1, 1) <> Mid(Cells(zeile + 1, 1), 1, 1) Then
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Text Text:="" & merker
Cells(zeile, 1).Comment.Visible = False
merker = 0
End If
Next zeile
End Sub
ups korrigiert :))
gruss nighty
Option Explicit
Sub makro01()
Dim zeile As Long
Dim merker As Long
Range("A1:A65535").ClearComments
For zeile = 2 To Sheets(1).UsedRange.SpecialCells(xlCellTypeLastCell).Row
merker = merker + Cells(zeile, 2)
If Mid(Cells(zeile, 1), 1, 1) <> Mid(Cells(zeile + 1, 1), 1, 1) Then
Cells(zeile, 1).AddComment
Cells(zeile, 1).Comment.Text Text:="" & merker
Cells(zeile, 1).Comment.Visible = False
merker = 0
End If
Next zeile
End Sub

