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
|
Sub cloturer()
Dim wsh As Worksheet, nbWsh As Integer, boucle As Integer, ligne As Integer
Dim f1 As String, f2 As String, f3 As String
nbWsh = 0
For Each wsh In Worksheets
If InStr(1, wsh.Name, "facturation") > 0 Then nbWsh = nbWsh + 1
Next
If nbWsh > 1 Then
f1 = "=facturation!L52" 'Montant HT
f2 = "=facturation!O52" 'TVA 5,5
f3 = "=facturation!P52" 'TVA 19,6
For boucle = 2 To nbWsh
If nbWsh > boucle Then
f1 = f1 & "+ facturation(" & boucle & ")!L52"
f2 = f2 & "+ facturation(" & boucle & ")!O52"
f3 = f3 & "+ facturation(" & boucle & ")!P52"
Else
ligne = Worksheets("facturation(" & boucle & ")").Cells(Rows.Count, 12).End(xlUp).Row
f1 = f1 & "+ L" & ligne
f2 = f2 & "+ O" & ligne
f3 = f3 & "+ P" & ligne
End If
Next
With Worksheets("facturation(" & nbWsh & ")")
Sheets("facturation").Rows("54:67").Cut .Cells(ligne + 2, 1)
.Cells(ligne + 2, 7).Formula = f2
.Cells(ligne + 3, 7).Formula = f3
.Cells(ligne + 4, 12).Formula = f1
.Cells(ligne + 5, 4).Validation.Delete
.Cells(ligne + 5, 4).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=" & .Range(.Cells(ligne + 4, 1), .Cells(ligne + 6, 1)).Address
.Cells(ligne + 6, 4).Validation.Delete
.Cells(ligne + 6, 4).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=" & .Range(.Cells(ligne + 10, 1), .Cells(ligne + 11, 1)).Address
.Cells(ligne + 8, 3).Validation.Delete
.Cells(ligne + 8, 3).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=" & .Range(.Cells(ligne + 13, 1), .Cells(ligne + 14, 1)).Address
End With
End If
End Sub |