Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA meaning of ampersand in range

Tags:

excel

vba

Im clueless on what the meaning of Range("B1:U" & y) is where y is

Dim y As Integer
y = Worksheets("Raw Data").Range("A2").End(xlDown).Row

What is the ampersand y doing here?

like image 692
woody Avatar asked Dec 20 '22 05:12

woody


1 Answers

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"

like image 85
borrillis Avatar answered Dec 31 '22 13:12

borrillis