Tag: 重构

如何重构比较循环在我的Excel VBA代码的速度?

我是Excel VBA的新手,没有太多的经验。 我有两个数据的工作表,我比较,然后如果一个值匹配我复制并粘贴到第二个工作表。 我使用for循环来比较每一行,并想知道是否有更好的方法来做到这一点? 我目前正在使用蛮力,并希望有一种方法,以便我的程序不会运行很长时间。 (我在不同的页上重复这段代码13次)。 基本上这个代码是在符合某些条件的情况下合并信息的。 以下是我的代码。 Sub consolidate(z) Sheets(z).Range("B1:AXH100").Delete '''deletes former values''' For i = 1 To 30 For x = 1 To 500 If IsEmpty(Sheets("Sheet1").Cells(x, 13)) Then 'if cell value is empty skip it' a = 1 Else: If Sheets("Sheet1").Cells(x, 18) = Sheets(z).Cells(1, 1) Then 'check to see if value is same' […]

加快包含计算的循环

更改后的代码(整个模块在这里) Sub Filter_TPDrop() ' ' Filter based on Voids and < 5 min times ' Dim LstRow, i, TestVoid, TestTime As Long Dim ActiveDate As Variant Dim NewData, delRange As Range Dim T1, T2 As Date With Application .Calculation = xlCalculationManual .ScreenUpdating = False End With ActiveDate = Worksheets("TPDrop").Range("H2").Value ' ' Sort the Table by […]