Private Sub CommandButton3_Click() 'Transfert ligne par ligne sur feuille choisie
Dim tablo(), i&, ligne&, x$, j As Variant
With [Tableau1]
ReDim tablo(1 To .Rows.Count, 1 To 1)
For i = 1 To .Rows.Count
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
For i = 0 To ListBox1.ListCount - 1
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
j = Application.Match(x, tablo, 0)
If IsNumeric(j) Then
[Tableau1].Rows(j).Copy .Rows(ligne) 'copier-coller
[Tableau1].Rows(j).Delete xlUp 'supprime la ligne
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