我的宏工作在一个体面的,但不是过多的数据量(<1000行与5-10列)。宏的速度似乎放慢了,这两个额外的列带有引用数据的公式,特别是这段代码。
lastrow = cells(rows.count,7).end(xlup).row
for i = 5 to lastrow
cells(i,8).formular1c1 = "=100*ln(rc[-1]/r[-1])"
next i
for i = 22 to lastrow
cells(i,9).formuar1c1 = "=stdev(r[-20]c[-1]:rc[-1])*(251)^.5"
next i
我发现这个宏与excel一起带来了反复出现的滞后问题。这里有人知道解决办法吗?或者提供一些加速宏的提示?
发布于 2014-01-24 16:31:49
您不需要为此使用循环。只需将公式应用于整个范围:
lastrow = Cells(Rows.Count, 7).End(xlUp).Row
Range("H5:H" & lastrow).FormulaR1C1 = "=100*ln(rc[-1]/r[-1])"
Range("I22:I" & lastrow).FormulaR1C1 = "=stdev(r[-20]c[-1]:rc[-1])*(251)^.5"
最好是增加一些lastrow
的检查
lastrow = Cells(Rows.Count, 7).End(xlUp).Row
If lastrow >= 5 Then Range("H5:H" & lastrow).FormulaR1C1 = "=100*ln(rc[-1]/r[-1])"
If lastrow >= 22 Then Range("I22:I" & lastrow).FormulaR1C1 = "=stdev(r[-20]c[-1]:rc[-1])*(251)^.5"
发布于 2014-01-24 16:31:12
尝试创建一些代码逻辑,这将使执行更快。公式有时会使执行过程被抛出。
https://stackoverflow.com/questions/21337598
复制相似问题