Add value to array based on if...then output in VBA
As an example:
store values from ar2 in ar3 if ar1 is 1 and < 10
Sub BBB()
Dim ar1(1 To 10), ar2(1 To 10), ar3()
ReDim ar3(1 To 1)
j = 0
For i = 1 To 10
ar1(i) = Int(Rnd() * 25 - 8)
ar2(i) = i * i
If ar1(i) 1 And ar1(i) < 10 Then
j = j + 1
ReDim Preserve ar3(1 To j)
ar3(j) = ar2(i)
End If
Next
For i = 1 To j
Debug.Print ar3(i)
Next
End Sub
--
Regards,
Tom Ogilvy
"Scott P" wrote in message
...
How do I add a value to an array (in VBA) based upon the output of an
if...then statement? I have two arrays -- if a certain value falls within a
range in array 1, I want to add the corresponding value in array 2 to a
third array, which I will use to hold values for later calculation.
Thanks in advance for your help.
|