【发布时间】:2014-07-24 13:44:04
【问题描述】:
我有一组 VBA 代码,它们非常适合大约 20 000 x 16 个单元格。 但是,我需要使用最多 80 000 x 16 个单元格的代码。
我发现了两种运行速度非常慢的代码:
c = 2 'this is the first row where your data will output
d = 2 'this is the first row where you want to check for data
Application.ScreenUpdating = False
Do Until Range("A" & c) = "" 'This will loop until column U is empty, set the column to whatever you want
'but it cannot have blanks in it, or it will stop looping. Choose a column that is
'always going to have data in it.
ws1.Range("U" & d).FormulaR1C1 = "=RC[-20] & RIGHT(""0000"" & RC[-14], 6)"
c = c + 1 'Advances a and b when there is a matching case
d = d + 1
Loop
Application.ScreenUpdating = True
End Sub
Sub OpenValue()
Dim l As Integer
Dim k As Integer
Dim m As Integer
m = Sheets("Input").Range("AC:AC").End(xlDown).Row
For l = 2 To m
If Range("AC" & l) = "Delievered" Then
Range("AD" & l) = 0
ElseIf Range("AC" & l) = "Cancelled" Then
Range("AD" & l) = 0
Else
Range("AD" & l) = Val(Range("Z" & l)) * Val(Range("J" & l))
End If
Next
End Sub
我能做些什么来优化它们......
【问题讨论】:
-
使用
Cells而不是Range,这样可以避免字符串连接(例如:Cells(l, 30)而不是Range("AD" & l)) -
这应该在 CodeReview.SE 中,而不是 StackOverflow 中。
-
问题属于代码审查