1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Sub toto()
Dim UnTab(1 To 20, 1 To 13)
Dim i As Long, j As Long
'remplissage du tableau pour avoir des données
For i = LBound(UnTab, 1) To UBound(UnTab, 1)
'on ne remplit pas la dernière colonne
For j = LBound(UnTab, 2) To UBound(UnTab, 2) - 1
UnTab(i, j) = i + j
Next j
Next i
' pour chaque ligne du tableau
For i = LBound(UnTab, 1) To UBound(UnTab, 1)
' la dernière colonne = la somme des autres colonnes de la ligne
UnTab(i, UBound(UnTab, 2)) = Application.WorksheetFunction.Sum(Application.Index(Application.Transpose(UnTab), , i))
Next i
' écriture du résultat pour vérifier
With ThisWorkbook
On Error Resume Next
Application.DisplayAlerts = False
.Worksheets("DEMO").Delete
Application.DisplayAlerts = True
On Error GoTo 0
With .Worksheets.Add
.Name = "DEMO"
.Cells(1, 1).Resize(20, 13).Value = UnTab
End With
End With
End Sub |
Partager