在VLookUp中添加变量 [英] Adding a variable inside VLookUp

查看:82
本文介绍了在VLookUp中添加变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用vlookup函数时遇到问题.第一个代码显示 VLOOKUP 知道什么是"TempArg'17" ,但是现在我想将其更改为字符串并将其写入 VLOOKUP ,所以我创建了一个字符串 temp .

I'm having a problem with a vlookup function. First code shows that VLOOKUP know what is "TempArg'17", but now I want to change it this text to string and write it inside VLOOKUP, so I created a string temp.

Dim temp As String
Dim num As Int
num = 17

temp = "TempArg" + "'" + Cstr(num)

这是起作用的旧代码:

ActiveCell.FormulaR1C1 = _
        "=VLOOKUP([@[" & Chr(10) & "Stevilka]],'TempArg''17'!C[-16]:C[-17],2,FALSE)"

这是我想要更改的代码,但它不起作用:

And here is the code that I want to change and that doesn't work:

ActiveCell.FormulaR1C1 = _
        "=VLOOKUP([@[" & Chr(10) & "Stevilka]],'" & temp & "'!C[-16]:C[-17],2,FALSE)"

这就是我得到的.

运行时错误"1004":

Run-time error '1004':

应用程序定义或对象定义的错误

Application-defined or object-defined error

推荐答案

缺少单引号'.
更改以下行:

There's a missing single quote '.
Change following line:

temp = "TempArg" + "'" + CStr(num)

temp = "TempArg" + "''" + CStr(num)

甚至更好

temp = "TempArg''" & CStr(num)

也将 Dim num As Int 设置为无效.
应该是 Dim num As Integer ,但是我想这是一个错字...

Also with Dim num As Int this won't run.
Should be Dim num As Integer instead, but I guess this is a typo...

这篇关于在VLookUp中添加变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆