Vlookup改变列索引号

我正在尝试更改Colnum-14的列索引号,但在我看的单元格中显示Colnum-14

有什么我错过了吗? 我知道match/index公式,但我必须使用vlookup

我的代码:

 Dim Colnum As Integer For Colnum = 15 To 16 Sheets("Sheet1").Cells(8, Colnum + 1).Formula = "=iferror(vlookup(" & Sheets("Sheet1").Cells(8, 3).Address(False, True) & ",'Sheet2'!" & Range(Cells(3, 2), Cells(20, 10)).Address & "," & "Colnum-14" & ",False), ""NA"")" Next Colnum 

您正在embedded一个string“Colnum-14”,而不是您的查找列的variablesColnum 。 尝试

 Sheets("Sheet1").Cells(8, Colnum + 1).Formula = "=iferror(vlookup(" & Sheets("Sheet1").Cells(8, 3).Address(False, True) & ",'Sheet2'!" & Range(Cells(3, 2), Cells(20, 10)).Address & "," & Colnum & ",False), ""NA"")"