有关如何加快循环速度的建议 [英] Suggestions on how to speed up loop

查看:68
本文介绍了有关如何加快循环速度的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码.我想知道是否有一种简单的方法可以重写它,从而减少运行时间?目前,我大约有13,000行要遍历,运行大约需要3-5分钟.谢谢!

I have the following code. I was wondering if there is an easy way to rewrite it so that it takes less time to run? Currently, I have about 13,000 rows to loop through and it takes approximate 3-5 minutes to run. Thanks!

Sheets("wkly").Activate

Dim i As Long

Lastrow = Range("A" & Rows.Count).End(xlUp).Row

For i = 2 To Lastrow


If Range("S" & i) > 0.005 Then
        Range("Z" & i, "AA" & i).Copy
        Range("AC" & i, "AD" & i).PasteSpecial xlPasteValues
End If

Application.ScreenUpdating = False
Next i

推荐答案

给出所有好的技巧,并包括以下内容.请尝试一下,看看可以实现多少性能提升.

Given all the good tips, and include the following too. Please give a try and see how much performance boost you could achieve.

Application.Calculation = xlCalculationManual

lastrow = Range("S" & Rows.Count).End(xlUp).Rows
For i = 1 To lastrow
    If Range("S1").Offset(i) > 0.005 Then
            Range("AC").Offset(i).Resize(1, 2).Value = Range("Z").Offset(i).Resize(1, 2).Value
    End If
Next i

这篇关于有关如何加快循环速度的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆