Performance 运行慢速公式宏
“我的宏”使用的数据量适中,但不会过多((尝试创建一些代码逻辑,以加快执行速度。公式有时会使执行陷入困境。不需要使用循环。只需将公式应用于整个范围:Performance 运行慢速公式宏,performance,vba,excel,Performance,Vba,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]:
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"
我尝试了你的第一个建议。效果很好!我没有使用支票,你能简单解释一下它的用途吗?如果最后一行是3,会是什么?你会得到一个范围
范围(“H5:H3”)
它等于范围(“H3:H5”)
您可能会丢失H3:H5
中的数据,因为它们将用公式重写。与Range(“I22:I”和lastrow)
的情况相同:对于lastrow=3,它将用公式重写Range(“I3:I22”)中的所有数据。
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"