Summe unter letzter zelle bilden
Hallo wie kann man per makro eine summe immer unter der letzten zelle in meiner tabelle bilden?
daten stehen in den spalten D bis BC.
Danke
Gruß
Tim
Antwort schreiben
Antwort 1 von Saarbauer vom 09.04.2020, 16:15 Options
Hallo,
musst du wahrscheinlich für jede Spalte extra machen oder als Schleife
Für Spalte D
Cells(Range("D65536").End(xlUp).Row + 1, 4).Formula = ("=SUM(R2C4:R" & Range("C65536").End(xlUp).Row & "C4)")
Wenndu es mit einer Schleife machst, dann
Cells(Range("D65536").End(xlUp).Row + 1, i).Formula = ("=SUM(R2C" & i & ":R" & Range("C65536").End(xlUp).Row & "C" & i & ")")
i steht für den Schleifen index und fängt mit 4 an und Spalte BC ist 55
Gruß
Helmut
Antwort 2 von Saarbauer vom 09.04.2020, 18:44 Options
Hallo,
habe noch einen Fehler festgestellt
Cells(Range("D65536").End(xlUp).Row + 1, 4).Formula = ("=SUM(R2C4:R" & Range("D65536").End(xlUp).Row & "C4)")
und dann
Cells(Cells(65536, i).End(xlUp).Row + 1, 4).Formula = ("=SUM(R2C4:R" & Cells(65536, i).End(xlUp).Row & "C4)")
Gruß
Helmut
Antwort 3 von Tim85 vom 10.04.2020, 09:17 Options
Hallo Helmut,
habe es jetzt so gebaut:
Sub Summe()
Cells(Range("D65536").End(xlUp).Row + 1, 4).Formula = ("=SUM(R2C4:R" & Range("D65536").End(xlUp).Row & "C4)")
Cells(Cells(65536, i).End(xlUp).Row + 1, 4).Formula = ("=SUM(R2C4:R" & Cells(65536, i).End(xlUp).Row & "C4)")
End Sub
Funktioniert leider so nicht...
Gruß
Tim
Antwort 4 von rainberg vom 10.04.2020, 09:59 Options
Hallo Tim,
hier mein Vorschlag:
Option Explicit
Sub summe()
Dim intSp As Integer
For intSp = 4 To 55 'Spalte D bis Spalte BC
Cells(Cells(Rows.Count, intSp).End(xlUp).Row + 1, intSp).Value _
= WorksheetFunction.Sum(Range(Cells(1, intSp), Cells(Cells(Rows.Count, intSp).End(xlUp).Row, intSp)))
Next
End Sub
Gruss
Rainer
Antwort 5 von Tim85 vom 10.04.2020, 10:06 Options
Hallo Rainer,
funktioniert bestens, allerdings fügt er nicht die Formel ein sondern nur den Wert.
da ich später mit der Tabelle arbeiten will, benötige ich die Summen-Formel.
Vielen Dank.
Gruß
Tim
Antwort 6 von rainberg vom 10.04.2020, 10:53 Options
Hallo Tim,
dann so:
Option Explicit
Sub summe()
Dim intSp As Integer
For intSp = 4 To 55
Cells(Cells(Rows.Count, intSp).End(xlUp).Row + 1, intSp).FormulaR1C1 _
= "=SUM(INDIRECT(CHAR(64+COLUMN())&ROW(R1)&"":""&CHAR(64+COLUMN())&ROW()-1))"
Next
End Sub
Gruss
Rainert
Antwort 7 von Tim85 vom 10.04.2020, 11:03 Options
Hallo,
ich weiß nicht warum, aber von Spalte AH bis AI funktioniert es nicht.
Dort steht leider:
#BEZUG!
Gruß
Tim
Antwort 8 von rainberg vom 10.04.2020, 11:50 OptionsLösung
Hallo Tim,
war ein Schuss in den Ofen, funktioniert logischer Weise nur bis Spalte Z.
Nimm diesen Code.
Option Explicit
Sub summe()
Dim intSp As Integer
For intSp = 4 To 55
Cells(Cells(Rows.Count, intSp).End(xlUp).Row + 1, intSp).FormulaR1C1 _
= "=SUM(INDIRECT(ADDRESS(ROW(R1),COLUMN())&"":""&ADDRESS(ROW()-1,COLUMN())))"
Next
End Sub
Gruss
Rainer
Antwort 9 von Tim85 vom 10.04.2020, 12:14 Options
Vielen, vielen DANK!!
Hast mir sehr geholfen!!!
Gruß
Tim