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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
Private Sub CommandButton1_Click()
Dim Ctrl As Control
Dim r As Integer
Dim Derligne As Integer
Dim Ind As Integer
Dim 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))
Derligne = .Range("A" & .Rows.Count).End(xlUp).Row + 1
If .Cells(Derligne - 1, 1).Value = "Total général" Then Derligne = Derligne - 1
.Range(.Cells(Derligne, 3), .Cells(Derligne, 5)).Merge
.Range(.Cells(Derligne, 7), .Cells(Derligne, 9)).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
With .Range(.Cells(Derligne, r), .Cells(Derligne, r).Offset(, 7))
.Borders(7).Weight = 2
.Borders(8).Weight = 2
.Borders(9).Weight = 2
.Borders(10).Weight = 2
.Borders(11).Weight = 2
.Interior.ColorIndex = 6
.Font.ColorIndex = 11
.Font.Bold = True
End With
End If
Next Ctrl
Derligne = .Cells(Rows.Count, 1).End(xlUp).Row + 1
.Cells(Derligne, 1).Value = "Total général"
.Cells(Derligne, 2).Formula = "=SUM(" & .Cells(12, 2).Address & ":" & .Cells(Derligne - 1, 2).Address & ")"
.Cells(Derligne, 2).NumberFormat = "#,##0.00"
With .Range(.Cells(Derligne, 1), .Cells(Derligne, 2))
.Borders(7).Weight = 2
.Borders(8).Weight = 2
.Borders(9).Weight = 2
.Borders(10).Weight = 2
.Borders(11).Weight = 2
.Interior.ColorIndex = 16
.Font.ColorIndex = 3
.Font.Bold = True
End With
End With
Next Ind
TextBox1.Text = ""
Unload Me
End Sub |
Partager