作者:kerrybrooks | 来源:互联网 | 2023-10-14 18:02
只是想知道是否有任何方法可以加快以下代码的速度?提前致谢
Sub Test()
Dim ws As Worksheet
Range("R28") = Mid(Range("Q7"), 55, 3) / 100
Range("R29") = Mid(Range("Q7"), 58, 3) / 100
Range("R30") = Mid(Range("Q7"), 61, 3) / 100
Range("R31") = Mid(Range("Q7"), 64, 3) / 100
Range("R32") = Mid(Range("Q7"), 67, 3) / 100
Range("R33") = Mid(Range("Q7"), 70, 3) / 100
Range("R34") = Mid(Range("Q7"), 73, 3) / 100
Range("R35") = Mid(Range("Q7"), 76, 3) / 100
Range("R36") = Mid(Range("Q7"), 79, 3) / 100
Range("R37") = Mid(Range("Q7"), 82, 3) / 100
End Sub
回答
或者试试这个
With Range("R28:R37")
.Formula = "=MID($Q$7, 55 + (ROW()-28) * 3, 3) / 100"
.Value = .Value
End With
或者下面让它动态?
With Range("R28:R37")
.Formula = "=MID($Q$7, 55 + (ROW()-" & .Row & ") * 3, 3) / 100"
.Value = .Value
End With
回答
有一个循环:
Dim cell As Range
For Each cell In Range("R28:R37")
Dim i As Long
cell.Value = Mid(Range("Q7").Value, 55 + i * 3, 3) / 100
i = i + 1
Next