与范围和2工作簿的Excel Vlookupmacros

我想要一个macros来运行从最后一行填充的vlookup。 下面的代码是获取最后一行被填充(J列)和最后一行填满(列A),下面的公式是获得这2列的最后一行;

Sub lookup() 'Find the last Row with data in a Column 'In this example we are finding the last row of column A (Filled) and J (to be filled) Dim lastRowA As Long Dim lastRowJ As Long With ActiveSheet lastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row lastRowJ = .Cells(.Rows.Count, "J").End(xlUp).Row End With MsgBox lastRowA & " " & lastRowJ End Sub 

vlookup在列C中查找值,并查看另一个excel文件C:\ LINKED [Roster_Iloilo.xlsx] ACTIVE'!$ C:$ E中的范围 。 查看文件的图片请使用vlookup需要帮助。

这是你正在尝试? (未testing)

你可以写你的公式

 "=vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)" 

 "=vlookup(C" & "40846" & ",'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)" 

所以你所要做的就是replace最后一行:)

 Sub Sample() Dim ws As Worksheet Dim lastRowA As Long Dim sFormulaPre As String Dim sFormulaSuff As String Set ws = ThisWorkbook.Sheets("Sheet1") '=vlookup(C40846,'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0) sFormulaPre = "=vlookup(C" sFormulaSuff = ",'C:\LINKED[Roster_Iloilo.xlsx]ACTIVE'!$C:$E,3,0)" With ws lastRowA = .Cells(.Rows.Count, "A").End(xlUp).Row MsgBox sFormulaPre & lastRowA & sFormulaSuff '~~> Usage '.Cells(1, 1).Formula = sFormulaPre & lastRowA & sFormulaSuff End With End Sub