Bonsoir tout le monde,
J'ai une petite demande, j'ai réalisé un algorithme qui calcule le cumul d'une table, l'algorithme que j'ai réalisé calcule seulement une seul colonne par contre moi je voulais calculer 3 colonne, le principe ce que je voulais et le suivant :
A1+B1+C1 =D1
A2+B2+C2+D1=D2
A3+B3+C3+D2=D3
etc...
Sub calculatCumuleScrap()
On Error Resume Next
Dim ws As Worksheet
Dim VisRng As Range, c As Range
Dim StartRow As Long
Dim LastRow As Long
Set ws = Sheet4
With ws
LastRow = .Cells(.Rows.Count, "AM").End(xlUp).Row '<-- get last row with data in Column K
StartRow = 9 '<-- init value
' set visible range to only filtered cells in Column G
Set VisRng = .Range(Range("AM" & StartRow), Range("AM" & LastRow)).SpecialCells(xlCellTypeVisible)
StartRow = VisRng.Item(1).Row '<-- update first row in visible range
For Each c In VisRng
If c.Row = StartRow Then
.Range("AN" & c.Row) = .Range("AM:" & c.Row).Value
Else
.Range("AN" & c.Row).Formula = "=SUBTOTAL(9,AM" & StartRow & ":AM" & c.Row & ")"
End If
Next c
End With
On Error GoTo 0
End Sub