我正在使用 VBA 计算成对斜率,将它们存储在一个数组中,然后使用 Chip Pearson 在工作表上转置数组的技术对它们进行排序。当斜率数超过 65K 时,我的代码将失败,这在 Excel 2003 中是有意义的,因为行数。我认为它可以在 Excel 2010 中工作,但我似乎有同样的问题。有谁知道 Resize 属性或 Transpose 方法是否有限制?
谢谢
Sub pairwise()
Dim endrow As Long, i As Long, j As Long, s As Long
Dim num As Double, denom As Double, sij As Double
Dim r As Range
Dim slopes()
endrow = Range("A1").End(xlDown).Row
n = endrow - 1
nrd = endrow * n / 2
ReDim slopes(nrd)
Debug.Print LBound(slopes); UBound(slopes)
For i = 1 To n
For j = (i + 1) To endrow
num = Cells(i, 2).Value - Cells(j, 2).Value
denom = Cells(i, 1).Value - Cells(j, 1).Value
If denom <> 0 Then
sij = num / denom
slopes(s) = sij
s = s + 1
End If
Next j
Next i
Set r = Range("C1").Resize(UBound(slopes) - LBound(slopes) + 1, 1)
r = Application.Transpose(slopes)
' sort the range
r.Sort key1:=r, order1:=xlAscending, MatchCase:=False
End Sub