我使用VBA来计算成对的山坡,将它们存储在一个数组,然后用换位上workheet阵列对它们进行排序的芯片Pearson的技术。我的代码在斜率数超过65K时失败,这在Excel 2003中是有意义的,这是由于行数。我认为它会在Excel 2010中工作,但我似乎有同样的问题。有谁知道Resize属性或Transpose方法是否存在限制?Excel VBA范围调整大小限制?
由于
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
非常酷。快速注,使用ReDim线应'使用ReDim aSlopes(1至lEndRow *(lEndRow-1)/ 2,1至1)' –
并且,通过阵列循环花费约45%的时间与通过细胞循环( 0.60秒与1.33秒),计算和分类65,341斜坡:) –
这就是我原来的ReDim,但是我跑出阵列的房间。我知道你会弄清楚细节。 :) –