Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1228to1232
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
Summenformel setzen
Kurt
Guten Abend,
ich weiß nicht ob man das kann, ich versuche es mal, die FRage zu stellen.
Ich habe eine Tabelle, siehe Anlage, in der Tabelle sind fette Unterstriche.
Unterhalb des Unterstriches soll die Summenformel eingesetzt werden aber
nach oben nur immer bis zur letzten Zeile unterhalb des Striches.
Die fetten Unterstriche fangen an ab Zeile 4, siehe hier ist ein dünner Unterstrich.
Die Tabelle kann wesentlich länger sein !
Habe mal Formel eingesetzt I11, I21 und I36 als Muster,
danke im Voraus für einen Tip.
https://www.herber.de/bbs/user/76699.xls
mfg Kurt P
AW: Summenformel setzen
20.09.2011 20:59:52
Josef

Hallo Kurt,
probiere mal.

Sub test()
  Dim lngRow As Long, lnglast As Long, lngStart As Long
  
  With ActiveSheet
    lnglast = .UsedRange.SpecialCells(xlCellTypeLastCell).Row
    lngStart = 5
    For lngRow = 5 To lnglast
      If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
        .Cells(lngRow, 9) = Application.Sum(.Range(.Cells(lngStart, 9), .Cells(lngRow - 1, 9)))
        'oder als Formel
        '.Cells(lngRow, 9).FormulaR1C1 = "=SUM(R[-" & lngRow - lngStart & "]C:R[-1]C)"
        lngStart = lngRow + 1
      End If
    Next
  End With
  
End Sub



« Gruß Sepp »

Anzeige
Guten Abend Sepp leider nur zumTeil
20.09.2011 21:21:03
Kurt
Guten Abend Sepp,
habe mal Makro eingefügt, ich brauch immer die Formel aber auch wenn die Tabelle
länger wird und nach Rechts, habe mal gelb makiert.
Danke !
https://www.herber.de/bbs/user/76700.xls
freundlichst kurt p
AW: Guten Abend Sepp leider nur zumTeil
20.09.2011 21:28:49
Josef

Hallo Kurt,
dann eben so.

Sub test()
  Dim lngRow As Long, lngLastRow As Long, lngStartRow As Long
  Dim lngStartCol As Long, lngLastCol As Long
  
  With ActiveSheet
    lngStartRow = 5 'erste Datenzeile
    lngStartCol = 9 'erste Datenspalte
    lngLastRow = Application.Max(lngStartRow, .UsedRange.SpecialCells(xlCellTypeLastCell).Row)
    lngLastCol = Application.Max(lngStartCol, .UsedRange.SpecialCells(xlCellTypeLastCell).Column)
    lngStartRow = 5
    For lngRow = lngStartRow To lngLastRow
      If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
        .Range(.Cells(lngRow, lngStartCol), .Cells(lngRow, lngLastCol)).FormulaR1C1 = "=SUM(R[-" & lngRow - lngStartRow & "]C:R[-1]C)"
        lngStartRow = lngRow + 1
      End If
    Next
  End With
  
End Sub



« Gruß Sepp »

Anzeige
Grandios !!! Tausend Dank
20.09.2011 22:14:49
Kurt
Guten Abend Sepp,
super Klasse,
Danke.
Ich habe daneben noch andere Werte, jetzt werden die Formeln bis nach Rechts
soweit wie geht kopiert.
Kann man dies einschränken ?
Also Spalte 9-19 ?
Könnte man dann noch doppelt unterstreichen ?
Dann kann ich mir das händige formatieren sparen ?
mfg Kurt P
AW: Grandios !!! Tausend Dank
20.09.2011 22:22:42
Josef

Hallo Kurt,
klar geht das auch.

' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit


Sub test()
  Dim lngRow As Long, lngLastRow As Long, lngStartRow As Long
  Dim lngStartCol As Long, lngLastCol As Long
  
  With ActiveSheet
    lngStartRow = 5 'erste Datenzeile
    lngStartCol = 9 'erste Datenspalte
    lngLastRow = Application.Max(lngStartRow, .UsedRange.SpecialCells(xlCellTypeLastCell).Row)
    lngLastCol = 19 'Application.Max(lngStartCol, .UsedRange.SpecialCells(xlCellTypeLastCell).Column)
    lngStartRow = 5
    For lngRow = lngStartRow To lngLastRow
      If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
        With .Range(.Cells(lngRow, lngStartCol), .Cells(lngRow, lngLastCol))
          .FormulaR1C1 = "=SUM(R[-" & lngRow - lngStartRow & "]C:R[-1]C)"
          .Borders(xlEdgeBottom).LineStyle = xlDouble
        End With
        lngStartRow = lngRow + 1
      End If
    Next
  End With
  
End Sub



« Gruß Sepp »

Anzeige
AW: Grandios !!! Tausend Dank
20.09.2011 23:28:29
Nepumuk
Servus Sepp,
für vorbildliche Variablendeklarationen gibt's ein Bienchen ins Muttiheft.
Userbild
Gruß
Nepumuk
Danke !!! -)
21.09.2011 07:19:44
Kurt
Guten Morgen Sepp,
tausend Dank, werde das nachher einsetzen und testen.
Ich denke aber das KLAPPT !!!
mfg kurt P
Guten Morgen, darf ich noch eine Nachfrage ?
21.09.2011 08:51:34
Kurt
Guten Morgen Sepp,
darf ich noch eine Nachfrage bzw. Erweiterung haben ?
In der Spalte 19 sollte die Quersumme gebildet werden, geht das auch ?
Anbei die Mustertabelle.
https://www.herber.de/bbs/user/76704.xls
mfg kurt p
Anzeige
AW: Guten Morgen, darf ich noch eine Nachfrage ?
21.09.2011 09:13:54
Reinhard
Hallo Kurt,
meinst du so:

Sub test()
Dim lngRow As Long, lngLastRow As Long, lngStartRow As Long
Dim lngStartCol As Long, lngLastCol As Long, intCharCount  As Integer
With ActiveSheet
lngStartRow = 5 'erste Datenzeile
lngStartCol = 9 'erste Datenspalte
lngLastRow = Application.Max(lngStartRow, .UsedRange.SpecialCells(xlCellTypeLastCell).Row)
lngLastCol = 19 'Application.Max(lngStartCol, .UsedRange.SpecialCells(xlCellTypeLastCell). _
Column)
For lngRow = lngStartRow To lngLastRow
If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
With .Range(.Cells(lngRow, lngStartCol), .Cells(lngRow, lngLastCol))
.FormulaR1C1 = "=SUM(R[-" & lngRow - lngStartRow & "]C:R[-1]C)"
.Borders(xlEdgeBottom).LineStyle = xlDouble
End With
With .Cells(lngRow, lngLastCol + 1)
.Value = ""
For intCharCount = 1 To Len(.Offset(0, -1).Value)
.Value = .Value + CInt(Mid(.Offset(0, -1).Value, intCharCount, 1))
Next intCharCount
End With
lngStartRow = lngRow + 1
End If
Next
End With
End Sub

Gruß
Reinhard
Anzeige
Leider nicht
21.09.2011 09:28:31
Kurt
Guten Morgen Reinhard, es sollte die Zeile von Spalte I bis Spalte R in der Spalte S
die Summe gebildet werden,
habe mich wohl Falsch ausgedrückt,
mfg kurt p
AW: Guten Morgen, darf ich noch eine Nachfrage ?
21.09.2011 09:18:32
Rudi
Hallo,
sicher geht das auch.

Sub test()
Dim lngRow As Long, lngLastRow As Long, lngStartRow As Long
Dim lngStartCol As Long, lngLastCol As Long
With ActiveSheet
lngStartRow = 5 'erste Datenzeile
lngStartCol = 9 'erste Datenspalte
lngLastRow = Application.Max(lngStartRow, .UsedRange.SpecialCells(xlCellTypeLastCell).Row)
lngLastCol = 19 'Application.Max(lngStartCol, .UsedRange.SpecialCells(xlCellTypeLastCell). _
Column)
lngStartRow = 5
For lngRow = lngStartRow To lngLastRow
If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
With .Range(.Cells(lngRow, lngStartCol), .Cells(lngRow, lngLastCol))
.FormulaR1C1 = "=SUM(R[-" & lngRow - lngStartRow & "]C:R[-1]C)"
.Borders(xlEdgeBottom).LineStyle = xlDouble
End With
lngStartRow = lngRow + 1
Else
.Cells(lngRow, 19).FormulaR1C1 = "=Sum(RC9:RC18)"
End If
Next
End With
End Sub

Gruß
Rudi
Anzeige
Danke auch an Reinhard -)
21.09.2011 09:33:03
Kurt
Hallo Rudi,
einfach nur perfekt, bin erstaunt was man so machen kann.
Danke an ALLE,
einen schönen Tag noch,
mfg kurt p
Habe gerade festgestellt
22.09.2011 16:24:26
Kurt
Hallo zusammen,
ich habe gerade festgestellt, die Summen in der Spalte 19 + 32(habe dazu genommen) ,
werden soweit reingesetzt über die letzte Summenzeile hinweg.
Die letzte Summenzelle ist in der Spalte I zu ermitteln oder für die Spalte 32 die letzte Summenzelle in
der Spalte V .

Sub SummenFormeln_setzen()
Dim lngRow As Long, lngLastRow As Long, lngStartRow As Long
Dim lngStartCol As Long, lngLastCol As Long
With ActiveSheet
lngStartRow = 5 'erste Datenzeile
lngStartCol = 9 'erste Datenspalte
lngLastRow = Application.Max(lngStartRow, .UsedRange.SpecialCells(xlCellTypeLastCell).Row)
lngLastCol = 19 'Application.Max(lngStartCol, .UsedRange.SpecialCells(xlCellTypeLastCell).  _
_
Column)
lngStartRow = 4
For lngRow = lngStartRow To lngLastRow
If .Cells(lngRow, 9).Borders(xlEdgeTop).Weight = -4138 Then
With .Range(.Cells(lngRow, lngStartCol), .Cells(lngRow, lngLastCol))
.FormulaR1C1 = "=SUM(R[-" & lngRow - lngStartRow & "]C:R[-1]C)"
.Borders(xlEdgeBottom).LineStyle = xlDouble
End With
lngStartRow = lngRow + 1
Else
'   .Cells(lngRow, 19).FormulaR1C1 = "=Sum(RC9:RC18)"           '"=SUM(RC[-10]:RC[-1])"
.Cells(lngRow, 19).FormulaR1C1 = "=SUM(RC[-10]:RC[-1])"
If ActiveSheet.Range("U4") = "" Then
Else
.Cells(lngRow, 32).FormulaR1C1 = "=SUM(RC[-10]:RC[-1])"
End If
End If
Next
End With
End Sub
mfg kurt P
Anzeige

167 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige