Sub import_data()
Dim T, dl As Long, i As Long, x, y, s As Double
With Sheets("Factures achats")
T = .Range("A4:H" & .Range("A65000").End(xlUp).Row).Value 'on remplit un Tableau avec la facture
End With
With Sheets("test")
dl = .Range("A65000").End(xlUp).Row
For i = LBound(T) To UBound(T)
x = Application.Match(T(i, 2), Sheets("Data").Columns(6), 0)
y = Application.Match(T(i, 4), Sheets("Data").Columns(9), 0)
If Not IsError(x) And Not IsError(y) Then
dl = dl + 1
.Cells(dl, 1) = CDate(T(i, 1))
.Cells(dl, 3) = Sheets("Data").Cells(x, 5)
.Cells(dl, 6) = T(i, 7)
.Cells(dl, 8) = T(i, 5)
s = T(i, 7)
If Not IsEmpty(T(i, 8)) Then
dl = dl + 1
.Cells(dl, 1) = CDate(T(i, 1))
.Cells(dl, 3) = 44566000
.Cells(dl, 6) = T(i, 8)
.Cells(dl, 8) = T(i, 5)
s = s + T(i, 8)
End If
dl = dl + 1
.Cells(dl, 1) = CDate(T(i, 1))
.Cells(dl, 3) = 40100000
.Cells(dl, 4) = Sheets("Data").Cells(y, 8)
.Cells(dl, 4).NumberFormat = "00000000"
.Cells(dl, 7) = s
.Cells(dl, 8) = T(i, 5)
End If
Next
End With
End Sub