Arrays 计算不同范围之间的差异,并在不写入工作簿的情况下查找前3个值
我试图让我的机器计算任意长度的两个数组之间的差,并返回1,2,3最大值。下面的代码适用于工作表上的范围Arrays 计算不同范围之间的差异,并在不写入工作簿的情况下查找前3个值,arrays,vba,foreach,Arrays,Vba,Foreach,我试图让我的机器计算任意长度的两个数组之间的差,并返回1,2,3最大值。下面的代码适用于工作表上的范围 Dim rng As Range, cell As Range Dim Value1 As Double, Value2 As Double, Value3 As Double Value1 = 0 Value2 = 0 Value3 = 0 For Each cell In rng If cell.Value > Value1 Then
Dim rng As Range, cell As Range
Dim Value1 As Double, Value2 As Double, Value3 As Double
Value1 = 0
Value2 = 0
Value3 = 0
For Each cell In rng
If cell.Value > Value1 Then
Value1 = cell.Value
value1row = cell.Row
value1col = cell.Column
End If
Next cell
For Each cell In rng
If cell.Value > Value2 And cell.Value < Value1 Then
Value2 = cell.Value
Value2Row = cell.Row
Value2Col = cell.Column
End If
Next cell
For Each cell In rng
If cell.Value > Value3 And cell.Value < Value2 Then
Value3 = cell.Value
Value3Row = cell.Row
Value3Col = cell.Column
End If
Next cell
另外,我们如何使数组大小动态
Dim CalcArray(1 to 100) as variant
For x = 1 to LastRow
CalcArray(x) = cells(i,1) - cells(i,2)
Next X