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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| Private Sub CommandButton1_Click()
Dim Ctrl As Control
Dim r As Integer
Dim Derligne As Integer
Dim LigneDebut As Long
Dim x As Integer, L As Integer, nombre_de_colonne As Integer
Dim Ligne As Long, Celluledebut As Integer, Cellulefin As Integer
Dim Celluledebut2 As Integer, Cellulefin2 As Integer
Dim Ind As Integer, sTabF() As String
' Définir le tableau des feuilles à modifier
sTabF = Split("Feuil1,Feuil2", ",")
' Pour chaque feuille
For Ind = 0 To UBound(sTabF)
' Avec la feuille "Ind"
With Worksheets(sTabF(Ind))
LigneDebut = 12
Derligne = .Range("A" & Cells.Rows.Count).End(xlUp).Row + 1
If .Cells(Derligne - 1, 1).Value = "Total général" Then Derligne = Derligne - 1
Ligne = Derligne
Celluledebut = 3: Cellulefin = 5
.Range(.Cells(Ligne, Celluledebut), .Cells(Ligne, Cellulefin)).Merge
Celluledebut2 = 7: Cellulefin2 = 9
.Range(.Cells(Ligne, Celluledebut2), .Cells(Ligne, Cellulefin2)).Merge
For Each Ctrl In UserForm1.Controls
r = Val(Ctrl.Tag)
If r > 0 Then
If Ctrl.Name = "TextBox2" Then
.Cells(Derligne, r) = Val(Ctrl)
.Cells(Derligne, r).NumberFormat = "#,##0.00"
Else
.Cells(Derligne, r) = Ctrl
End If
End If
Next
' Mettre le total du tableau
nombre_de_colonne = 2
L = .Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To nombre_de_colonne
.Cells(L + 1, x).Formula = "=SUM(" & .Cells(12, x).Address & ":" & .Cells(L, x).Address & ")"
.Cells(L + 1, x).NumberFormat = "#,##0.00"
.Cells(L + 1, x - 1).Value = "Total général"
Next
End With
Next Ind
TextBox1 = ""
Unload Me
End Sub |
Partager