2015-04-23 87 views
1

我想改变vlookup的列索引号,但是在我看到的单元格中显示Colnum-14Vlookup可变列索引号

有什么我错过了吗?我知道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 
+2

更改' “Colnum-14”'只'Colnum':'范围(将细胞(3,2),将细胞(20,10))地址& “” &“Colnum。 -14“&”'。 – Manhattan

+0

@TheLaughingMan当我接到一个电话时,我发布了下面的答案 - 所以我错过了你的评论 – brettdj

+0

@TheLaughingMan感谢您的帮助!:) – user1204868

回答

2

你嵌入一个字符串“Colnum-14”而不是您的查阅列变量Colnum。尝试在该部分

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"")" 
+0

@brettdi谢谢你的帮助!:) – user1204868