Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 可变列索引数_Vba_Excel - Fatal编程技术网

Vba 可变列索引数

Vba 可变列索引数,vba,excel,Vba,Excel,我试图更改vlookup的列索引号,但它在我正在查看的单元格中为我显示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(

我试图更改vlookup的列索引号,但它在我正在查看的单元格中为我显示
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

您正在为查找列嵌入字符串“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"")"

将本部分中的
“Colnum-14”
更改为仅
Colnum
范围(单元格(3,2),单元格(20,10))。地址和“,”和“Colnum-14”&”“
@TheLaughingMan我接到一个电话时,正在把答案贴在下面-所以我错过了你的评论。@TheLaughingMan谢谢你的帮助!:)@brettdj没有问题。非常想念这个标签,所以回来了。;)