vba vlookup填写到最后一行

时间:2017-02-24 13:28:34

标签: excel vba excel-vba vlookup

我是这个VBA的新手,需要一些关于我的代码的帮助。我设法从O列的最后一行获取代码到vlookup,但我不知道如何填充它以匹配E列的最后一行。

我的目标是从O填充的最后一行到E

的最后一行进行vlookup
if (Number(j)<=Number(holiday_ends)){
    console.log("TRUE");
}

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您可以通过清除Select / SelectionActivate / ActiveCell来解决问题。

以下是您清理过的代码并使其更加清晰:

Dim JPNpart As String, PartNumber As String, myRange As String, LastRow As Long
JPNpart = "[JPN_part.xlsx]Sheet1"
myRange = "'" & JPNpart & "'!A:G"

With ThisWorkbook.Sheets("Sheet1")
    'For column O
    LastRow = .Range("O" & .Rows.Count).End(xlUp).Row
    PartNumber = "B" & LastRow + 1
    .Range("O" & LastRow).Offset(1, 0).Formula = "=VLOOKUP(" & PartNumber & "," & myRange & ", 7, FALSE)"

    'For column E
    LastRow = .Range("E" & .Rows.Count).End(xlUp).Row
    PartNumber = "B" & LastRow + 1
    .Range("E" & LastRow).Offset(1, 0).Formula = "=VLOOKUP(" & PartNumber & "," & myRange & ", 7, FALSE)"
End With 'ThisWorkbook.Sheets("Sheet1")