Loops #VBA Vlookup循环中遇到不适用
我试图在循环中运行一个Vlookup函数。前两个数据(i=3)恢复得很好,但在循环过程中(我确信源文件中存在条件),其他数据(i=10…=>(#N/A))出现错误,因为上下文丢失。你看到我的逻辑有错误吗? 提前感谢您的回答, 阿尔芒Loops #VBA Vlookup循环中遇到不适用,loops,vlookup,na,Loops,Vlookup,Na,我试图在循环中运行一个Vlookup函数。前两个数据(i=3)恢复得很好,但在循环过程中(我确信源文件中存在条件),其他数据(i=10…=>(#N/A))出现错误,因为上下文丢失。你看到我的逻辑有错误吗? 提前感谢您的回答, 阿尔芒 Sub RAP() Dim directory As String, fileName As String, sheet As Worksheet, i As Integer, j As Integer Application.ScreenUpdating = F
Sub RAP()
Dim directory As String, fileName As String, sheet As Worksheet, i As Integer, j As Integer
Application.ScreenUpdating = False
'Initialisation of file
directory = "C:\Test"
'Building source filename
Date_fich = Format(Cells(2, 3), "yyyymmdd")
'defining the name of source file
Rac_fich = "MOP-sourcefile"
'Name
fileName = directory & Rac_fich & Date_fich & ".xlsx"
Cells(1, 10) = Date_fich
Cells(1, 11) = fileName
'Files
Dim mat As Workbook
Dim mat_w As Worksheet
Dim mat_source As Worksheet
'Source
Dim mhga As Workbook
Dim mhga_w As Worksheet
'searching zone
Dim plage_rech As Range
'variables
Set mat = ActiveWorkbook
ThisWorkbook.Activate
Set mat_w = mat.Worksheets("Test")
'last line
Dim der_ligne As Long
der_ligne = mat_w.Range("A" & Rows.Count).End(xlUp).Row
'Opening mhga (source)
Set mhga = Application.Workbooks.Open(fileName)
Set mhga_w = mhga.Worksheets("Source")
'copy of the source
mhga_w.Copy after:=mat_w
Set mat_source = mat.Worksheets("Source")
Set plage_rech = mat_source.Range("B1:J184")
For i = 3 To der_ligne Step 7
mat_w.Range("C" & i).Value = Application.VLookup(mat_w.Range("A" & i)
.Value, plage_rech, 9)
mat_w.Range("C" & i + 1).Value = Application.VLookup(mat_w.Range("A" &
i).Value, plage_rech, 8)
Next
'Closing the source file
mhga.Close (False)
Application.ScreenUpdating = True