Michelle M
asked on
Concatenating variant arrays in Excel VBA
Hello,
I would like to concatenate 2 variant arrays in Excel VBA for use in a For loop. The first array is basically the n-1 index for the array that I would like to create in the For loop. I have this working in Matlab which I am much more familiar with but need to get this into my Excel VBA code.
My incomplete VBA code is as follows:
If it would be helpful to understand what I am aiming for, my Matlab code is as follows:
I have verified that what I am getting out of TmpArr in VBA matches what I want and get out of the Matlab code for tmpArr.
Any help would be greatly appreciated!
I would like to concatenate 2 variant arrays in Excel VBA for use in a For loop. The first array is basically the n-1 index for the array that I would like to create in the For loop. I have this working in Matlab which I am much more familiar with but need to get this into my Excel VBA code.
My incomplete VBA code is as follows:
Dim numTimes As Integer
Dim area As Double
Dim endTime As Double
numTimes = Range("B2").Value 'This value is equal to 8
area = Range("B6").Value 'This value is equal to 150
endTime = 200
Dim TmpArr() As Variant
ReDim TmpArr(1 To numTimes)
TmpArr(1) = area/2
TmpArr(2) = area + 1.25
For idx1 = 3 To numTimes
TmpArr(idx1) = TmpArr(idx1 - 1) + 25.125
Next idx1
' Need to concatenate tmpArr here with some preallocated array (to be created)
' array of size (numTimes x endTime-1) then perform For loop
If it would be helpful to understand what I am aiming for, my Matlab code is as follows:
numTimes = 8;
area = 150;
endTime = 200;
tmpArr = zeros(numTimes,1);
tmpArr(1) = area/2;
tmpArr(2) = area + 1.25;
for idx1 = 3:numTimes
tmpArr(idx1) = tmpArr(idx1-1) + 25.125;
end
arr = [tmpArr zeros(numTimes, endTime-1)];
for idx2 = 2:1:endTime
isFast = arr(:,idx2-1) > 0 & arr(:,idx2-1) < (200-area);
dR = (2.*isFast + 0.5.*(~isFast));
arr(:,idx2) = mod(arr(:,idx2-1) + dr,200);
end
I have verified that what I am getting out of TmpArr in VBA matches what I want and get out of the Matlab code for tmpArr.
Any help would be greatly appreciated!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.