真的很慢For循环 [英] Really slow For loop
本文介绍了真的很慢For循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何更快地设置循环?
我有4列和超过250行,并且需要大约5分钟的时间来循环:
I have 4 columns and more than 250 rows and it takes like 5 minutes to loop this:
Application.Calculation = xlCalculationManual
Call CPU0
Dim TableA As Range: Set TableA = Range("L_PriceA")
With TableA
LongA = TableA.Rows.Count
For s = 1 To LongA
.Cells(s, 3).Value = "dynamic"
.Cells(s, 4).Value = "dynamic"
.Cells(s, 5).Value = "dynamic"
.Cells(s, 6).Value = "dynamic"
Next
End With
动态"将是xml中的数据,因为没有人通过 THIS 来帮助我,并且我不知道 :/.还研究了stackO中的一些循环问题,但没有主要的提升.
"dynamic" will be data from xml because nobody helped me with THIS and I don't know :/. Also looked at some loop problems here in stackO, but no main boost.
推荐答案
在范围内循环较慢.通过将数据移动到Variant Array来避免这种情况,
Looping over a range is slow. Avoid it by moving your data to Variant Array, something like this:
Dim dat As Variant
Dim s As Long
With TableA
LongA = .Rows.Count
dat = .Value ' TableA must be at least 6 columns wide
For s = 1 To LongA
dat(s, 3) = "dynamic"
dat(s, 4) = "dynamic"
dat(s, 5) = "dynamic"
dat(s, 6) = "dynamic"
Next
TableA.Value = dat
End With
这篇关于真的很慢For循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文