我使用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,但是我跑出陣列的房間。我知道你會弄清楚細節。 :) –