繁体   English   中英

运行慢速公式宏

[英]Running a slow formula macro

我的宏只能处理不错的数据,但不能处理过多的数据((<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反复出现滞后问题。 这里有人知道解决方法吗? 还是提供一些加速宏的技巧?

尝试创建一些代码逻辑,这将使执行速度更快。 公式有时会使执行过程陷入困境。

您不需要为此使用循环。 只需将公式应用于整个范围:

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"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM