Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Performance 运行慢速公式宏_Performance_Vba_Excel - Fatal编程技术网

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"