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
| Private Sub CommandButton4_Click()
Dim Nom1 As String
Dim Nom2 As String
Dim Nom3 As String
Dim i As Long
Dim max1 As Long
Dim max2 As Long
'j'ouvre les deux classeur
Nom1 = ThisWorkbook.Name 'Fichier1.xls
Call Ouvre
Nom2 = ActiveWorkbook.Name ' fichier2.xls qui contient la liste des fournisseurs
Windows(Nom2).Activate
max2 = Range("E65536").End(xlUp).Row
For i = 1 To max2
fournisseur = Workbooks(Nom2).Worksheets("Master Extraction").Range("G" & i).Value
Workbooks(Nom2).Worksheets("Master Extraction").Range("$A$3:$BD$37066").AutoFilter Field:=26, Criteria1:=fournisseur
Rows("1:300").Select
Selection.Copy
Workbooks.Add
Nom3 = ActiveWorkbook.Name
Windows(Nom3).Activate
Workbooks(Nom2).Worksheets("Master Extraction").Range("A1").Select
Workbooks(Nom2).Worksheets("Master Extraction").Paste
' Sauvegarde du document
With ActiveDocument
.SaveAs "C:\Users\gmellet\Documents\" & fournisseur & ".xls"
.Close
End With
Next i
Application.ScreenUpdating = True
End Sub |
Partager