VBA 范围内与号的含义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16822875/
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
VBA meaning of ampersand in range
提问by woody
Im clueless on what the meaning of Range("B1:U" & y)
is where y is
我对Range("B1:U" & y)
y在哪里的含义一无所知
Dim y As Integer
y = Worksheets("Raw Data").Range("A2").End(xlDown).Row
What is the ampersand y doing here?
符号 y 在这里做什么?
回答by borrillis
The ampersand is the Concatenation operator in the Visual Basic based languages, like VBA, in your case you are taking the string "B1:U" and concatenating the value of the variable y to the end of the string. Since y is defined as an Integer, VBA will first convert the value of y to a string and then perform the concatenation. For Example, if the value of y is 15, since that is the last cell in the range "A2" on the worksheet "Raw Data" then the concatenation of "B1:U" & y would be "B1:U15"
&符号是基于 Visual Basic 的语言(如 VBA)中的连接运算符,在您的情况下,您将使用字符串“B1:U”并将变量 y 的值连接到字符串的末尾。由于 y 被定义为整数,因此 VBA 将首先将 y 的值转换为字符串,然后执行连接。例如,如果 y 的值为 15,因为这是工作表“原始数据”上“A2”范围内的最后一个单元格,那么“B1:U”和 y 的串联将是“B1:U15”