我在函數中有一堆循環,它們循環遍歷一個我定義爲動態範圍的數組。下面是我想達到將範圍放入數組以獲得更高效的循環
Dim myArray As Range
myArray(x, j) 'So the array loops through each column and then each row in that column
For i = 1 to lastRow
If myArray(x, j).Value = myArray(x, i).Value Then
'Do something
我有一堆這些迴路的一些僞代碼,它是與100+行的數據集超慢。基本上無論在哪裏,我都將myArray定義爲Range,我想將其更改爲Variant,以便我可以a)遍歷數組,並b)使用該數組檢查值是否相同,而不是檢查範圍,這可能是性能問題的根本原因時,有200行* 500列
編輯
我如何轉換動態定義的範圍到一個數組?
我需要做這樣的事嗎?
lastRow = UBound(myArray, 1)
lastColumn = UBound(myArray, 2)
然後
If myArray(x, j) = myArray(x, i) Then
'Do something
那麼你的問題是什麼?並意識到「我怎麼能做到這一點?」太寬泛了。 –
@ScottCraner公平點,給我一秒鐘,我會添加更多的代碼來澄清 – MJ95