Excel vba - 将字符串转换为数字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7615629/
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
Excel vba - convert string to number
提问by user960358
So, I used the left function to take the first 4 characters of a string and I need to run a vlookup with it, but it won't find the match because it's looking through numbers.
所以,我使用 left 函数来获取字符串的前 4 个字符,我需要用它运行 vlookup,但它找不到匹配项,因为它正在查看数字。
I want to do this in a macro, so I'm not sure about the syntax. Can someone help?
我想在宏中执行此操作,所以我不确定语法。有人可以帮忙吗?
回答by asalamanca
If, for example, x = 5 and is stored as string, you can also just:
例如,如果 x = 5 并存储为字符串,您也可以:
x = x + 0
x = x + 0
and the new x would be stored as a numeric value.
并且新的 x 将存储为数值。