VLOOKUP 不适用于 VBA 之前的所有行

VLOOKUP not applying to all the rows through VBA

我正在使用 2 张工作表将 VLOOKUP 应用于一列。该代码有效,但仅应用于一个单元格。我想应用于 header 以下的所有单元格。 下面是我要执行的代码:

ESheet.Range("C2").Formula = "=VLOOKUP(B2, Roles!$A:$B, 2, FALSE)"

请使用此代码:

Sub VlookupAlColumn()
 Dim ESheet As Worksheet, lastR As Long
 'Set ESheet = ActiveSheet 'only for me, for testing reason
 lastR = ESheet.Range("C" & Cells.Rows.Count).End(xlUp).row
 ESheet.Range("C2:C" & lastR).Formula = "=VLOOKUP(B2, Roles!$A:$B, 2, FALSE)"
End Sub