Hello, I have the below code (OptimumSpeed) which works well but is a bit slow when applied to 8760 rows. I was trying to change it using Lbound to Ubound but can't seem to make it work (see second code Optimum) when trying to associate it with a Do until....Loop. Appreciate if anybody could help me solve this.
Thanks in advance
Thanks in advance
VBA Code:
Sub OptimumSpeed()
Application.ScreenUpdating = False
Dim i As Long
Dim rng, rng1, rng2, rng3 As Range
Set rng = Range("A1:A8760")
Set rng1 = Range("B1") '' this cell has a formula linked to C1 value
Set rng2 = Range("C1") '' this cell has a formula linked to D1 value
Set rng3 = Range("D1")
i = 0
For Each cell In rng
Do Until rng1.Offset(i, 0) > rng2.Offset(i, 0)
rng3.Offset(i, 0) = rng3.Offset(i, 0) - 1
Loop
i = i + 1
Next cell
Application.ScreenUpdating = True
End Sub
VBA Code:
Sub optimum()
Dim arr(),
Dim j As Long
arr = Range("A1:A8760")
For i = LBound(arr, 1) To UBound(arr, 1)
Do Until Range("B1").Offset(j , 0) > Range("C1").Offset(j , 0)
arr(i, 1) = Range("Temp_CtSPeed1").Offset(j , 0) - 1
Loop
j = j + 1
Next i
Range("A1:A8760")= arr
End Sub