I found a line of code that goes through all items in arrays without looping. The line of code writes the result to a range in a worksheet.
I would like to know if there is a way to write the results, separated by commas, to a string.
I would like three strings in total. One string = to the contents of ArrayA, second string = contents of ArrayB, and a third string = to the results currently displayed to a worksheet.
I can do all of that with loops, but I was wondering if there is a way to change the no loop line of code to save to the strings that I mentioned.
Here is the code example that shows the looping version as well as the one line of code that doesn't loop:
I would like to know if there is a way to write the results, separated by commas, to a string.
I would like three strings in total. One string = to the contents of ArrayA, second string = contents of ArrayB, and a third string = to the results currently displayed to a worksheet.
I can do all of that with loops, but I was wondering if there is a way to change the no loop line of code to save to the strings that I mentioned.
Here is the code example that shows the looping version as well as the one line of code that doesn't loop:
VBA Code:
Sub NoLoopThroughArrayValues()
Dim ArrayCount As Long
Dim I As Long
Dim ArrayA As Variant
Dim ArrayB As Variant
'
ArrayA = Array(1, 2, 3, 4, 5)
ArrayB = Array(2, 4, 6, 8, 10)
ArrayCount = UBound(ArrayA) + 1
'
'
' Loop version for arrays
For I = 1 To ArrayCount
Range("D" & I) = ArrayA(I - 1) * ArrayB(I - 1)
Next
'
'
' Or No Loop version for arrays equivalent
Range("E1").Resize(ArrayCount) = Evaluate("{" & Join(ArrayA, ";") & "} * {" & Join(ArrayB, ";") & "}")
'
End Sub