带有字符串参数的 VBA 评估函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28767103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 06:22:53  来源:igfitidea点击:

VBA Evaluate function with string arguments

excelvbaevaluate

提问by Mats Olsson

I have this function working ( It returns the row where the text DK001 sits in the ID range)

我有这个函数工作(它返回文本 DK001 在 ID 范围内的行)

Found = Application.Evaluate("=IF(ID=""DK001"",ROW(ID),""x"")")

I would like to feed the searchcriteria (e.g. DK001) as a string, like

我想将搜索条件(例如 DK001)作为字符串提供,例如

Found = Application.Evaluate("=IF(ID=SearchString,ROW(ID),""x"")")

I fail in creating a string that is accepted as a search criteria. I need your help on this! What am I doing wrong?

我无法创建被接受为搜索条件的字符串。我需要你的帮助!我究竟做错了什么?



This Evaluate function is haunting me ....

这个评估功能困扰着我......

What if I now wanted to send a value (not a string) to the function?

如果我现在想向函数发送一个值(不是字符串)怎么办?

Found = Application.Evaluate("=IF(ID=1,ROW(ID),""x"")")

The above works!

以上作品!

But if I want this to be a variable like

但如果我希望这是一个变量

Found = Application.Evaluate("=IF(ID=MyValue,ROW(ID),""x"")")

What then?

然后怎样呢?

回答by Alex K.

Double "to include them as literals:

Double"将它们包含为文字:

SearchString = "DK001"
Found = Application.Evaluate(""=IF(ID=""" & SearchString & """,ROW(ID),""x"")")

回答by izzymo

Could you try

你能不能试试

Application.Evaluate("=IF(ID="" & searchsrtring & "",ROW(ID),""x"")")