我想在数组中收集循环的结果。理想情况下,我会保留第一个循环的结果并将其与第二个循环的结果进行比较。如果第二个循环的结果更好,那么我想保留第二个,将其与第三个进行比较,依此类推。关于如何做到这一点的任何想法?这是我到目前为止的摘录:
For Each ccell In pcrange
If ccell.Cells.Value = 0 Then
For Each agecell In agerange
If agecell.Cells.Value < 0.5 And agecell.Offset(0, 5).Value > 1 Then
tmpyr = agecell.Offset(0, 1)
srchyr = ccell.Offset(0, -6)
tmpval = agecell.Offset(0, 2)
tmpdiff = Abs(tmpyr - srchyr)
arrindx = arrindx + 1
End If
tmparray = Array(tmpdiff, tmpval) 'need redim to hold more than 2 values? why are subsequent elements empty?
ReDim Preserve tmparray(2 * arrindx - 1)
'minarr = IIf(tmparray(2) > tmparray(0), tmparray(1), tmparray(3)); want to extract corresponding tmpval from array onto sheet if tmpdiff is the min of the entire loop; change to store better result each time
Next
End If
Next