Private Sub CommandButton3_Click() 'Transfert ligne par ligne sur feuille choisie
Dim tablo(), ub&, i&, ligne&, lig&, x$, j&
With [Tableau1]
ReDim tablo(1 To .Rows.Count, 1 To 1)
ub = UBound(tablo)
For i = 1 To ub
tablo(i, 1) = .Cells(i, 1) & .Cells(i, 2) & .Cells(i, 3) & .Cells(i, 4) & .Cells(i, 5)
Next
End With
For i = 1 To 9
If Me("OptionButton" & i) Then Exit For
Next
If i = 10 Then MsgBox "Choisissez une feuille pour le transfert...": Exit Sub
With Sheets(Me("optionButton" & i).Caption)
If .FilterMode Then .ShowAllData 'si la feuille est filtrée
ligne = .Range("A" & .Rows.Count).End(xlUp).Row + 1 '1ère ligne vide
lig = ligne
For i = ListBox1.ListCount - 1 To 0 Step -1 'boucle en remontant
If ListBox1.Selected(i) Then
With ListBox1: x = .List(i, 0) & .List(i, 1) & .List(i, 2) & .List(i, 3) & .List(i, 4): End With
For j = ub To 1 Step -1 'boucle en remontant
If tablo(j, 1) = x Then Exit For
Next
If j <= ub Then
[Tableau1].Rows(j).Copy
.Rows(lig).Insert 'insère les cellules copiées
.Cells(lig, 1).Validation.Delete 'supprime la liste de validation éventuelle
[Tableau1].Rows(j).Delete xlUp 'supprime la ligne
tablo(j, 1) = Chr(1) 'neutralise la ligne du tableau
ligne = ligne + 1
End If
End If
Next
.Cells(ligne, 2) = "Total"
.Cells(ligne, 3) = "=SUM(C1:C" & ligne - 1 & ")"
.Cells(ligne, 3).NumberFormat = "#,##0.00"
.Cells(ligne, 2).Resize(, 2).Font.Bold = True 'gras
.Visible = xlSheetVisible 'si la feuille est masquée
Application.GoTo .[A1]
End With
Unload UserForm1
End Sub