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
| Private Sub CommandButton1_Click()
Dim Fsource As Excel.Workbook
Dim ws As Worksheet
Dim w As Worksheet
Dim Ref As Long
Dim chemin As String
Dim nb_lig As Integer
Dim Qty As Integer
Dim trouv As Boolean
Dim s As Integer
'For Each Fsource In Application.Workbooks
While ouvert <> True
chemin = Application.GetOpenFilename 'ouvrir une une fenetre qui permet de selectionner le fichier excel
Set Fsource = Workbooks.Open(Filename:=chemin) 'ouvrir le fichier excel qui contient la BDD
Set ws = Fsource.Worksheets("BDD")
ouvert = True
Wend
Set w = Workbooks("destination.xlsm").Worksheets("Feuil2")
nb_lig = ws.Range("A" & Rows.Count).End(xlUp).Row 'compter le nombre des lignes
j = w.Range("A" & Rows.Count).End(xlUp).Row + 1 'Trouver la cellule active
Ref = Me.TextBox2
Qty = Me.TextBox1
With ws
For i = 4 To nb_lig
If Ref = .Cells(i, 3).Value Then 'Si le reference = à la valeur de la troisième colonne dans la feuille des données on remplie le tableau
trouv = True
w.Cells(j, 1) = j - 4
w.Cells(j, 3) = Ref
w.Cells(j, 5) = Qty
w.Cells(j, 2) = .Cells(i, 1)
w.Cells(j, 6) = .Cells(i, 4)
w.Cells(j, 7) = .Cells(i, 5)
w.Cells(j, 8) = .Cells(i, 6)
w.Cells(j, 9) = .Cells(i, 7)
w.Cells(j, 10) = .Cells(i, 8)
w.Cells(j, 11) = .Cells(i, 9)
w.Cells(j, 12) = .Cells(i, 10)
w.Cells(j, 13) = .Cells(i, 11)
End If
Next i
End With
If trouv = False Then
MsgBox ("verifiez votre saisie")
End If
Unload Me
End Sub |
Partager