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
| Sub dataext()
Dim main As Workbook
Set main = ThisWorkbook
Dim mainws As Worksheet 'Main worksheet
Set mainws = main.Worksheets("XXX")
Dim wB As Workbook 'Extract source
Workbooks.Open Filename:=(Range("A1")) 'Ouvrir le fichier cible
Set wB = Workbooks.Open(Filename:=Range("A1"))
Dim myLookupValue As String
Dim myFirstColumn As Long, myLastColumn As Long
Dim myColumnIndexprd As Long, myColumnIndexdev As Long
Dim myFirstRow As Long, myLastRow As Long
Dim myVLookupResult As Long
Dim myTableArray As Range
myLookupValue = [Table2].Item(Z, 1) 'id ref
myFirstColumn = 1
myLastColumn = 7
myColumnIndex1 = j 'i et j sont mes indices headers que je détermine à l'aide d'une autre routine, elle marche je ne l'ai pas intégrée dans cet extract de code pour que ça ne fasse pas trop lourd
myColumnIndex2 = i
myFirstRow = 3
myLastRow = wB.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row - 1
With wB.Sheets(1)
Set myTableArray = Range(Cells(myFirstRow, myFirstColumn), Cells(myLastRow, myLastColumn))
End With
For Z = 3 To last_row_main 'from line 3 to last row in main file
[Table2].Item(Z, i) = WorksheetFunction.IfNa(WorksheetFunction.VLookup(myLookupValue, myTableArray, myColumnIndex1, False), 0) 'error 1004 here
[Table2].Item(Z, j) = WorksheetFunction.IfNa(WorksheetFunction.VLookup(myLookupValue, myTableArray, myColumnIndex2, False), 0)
Next
wB.Close False ' ferme sans sauver
Set wB = Nothing
Set mainws = Nothing
End Sub |
Partager