2 things to speed this up.
Firstly, this check:
If .Range("CE5") = "DIST" Then
should be out of the loop, because the result doesn't change in the loop.
It means it has to be checked only once and not 2000 times.
The same applies to this value
..Cells(5, 86).Value
No need to get this value 2000 times.
Seconly, I would put the ranges in arrays, do the checking and altering in
these arrays
and then write the altered array back to the sheet. Array manipulations are
always much
faster then range manipulations.
With these 2 things your code would be something like this:
Sub test()
Dim i As Long
Dim LR As Long
Dim arr1()
Dim arr2()
Dim strMainCheck As String
Dim dNumberCheck As Double
LR = 2000
With Sheets(1)
.Columns("Y").NumberFormat = "0"
strMainCheck = .Cells(5, 83).Value
dNumberCheck = .Cells(5, 86).Value
arr1 = Range(.Cells(3, 25), .Cells(LR, 25))
arr2 = Range(.Cells(3, 57), .Cells(LR, 57))
If strMainCheck = "DIST" Then
For i = 1 To LR - 2
If dNumberCheck - arr1(i, 1) > 0 Then
arr2(i, 1) = dNumberCheck - arr1(i, 1)
Else
arr2(i, 1) = 0
End If
Next
Range(.Cells(3, 57), .Cells(LR, 57)) = arr2
End If
End With
End Sub
You will have to work it out a bit further, but this should make it much
faster.
RBS
The following code takes a R E A L L Y long time (90 seconds), processing
around 2000 records. Is there any way to speed it up?
.Columns("Y").NumberFormat = "0"
For i = 3 To (numberofRows - 2)
If .Range("CE5") = "DIST" Then
If .Cells(5, 86).Value - .Cells(i, 25).Value > 0 Then
.Cells(i, 57).Value = .Cells(5, 86).Value - .Cells(i, 25).Value
Else
End If
.Cells(i, 57).Value = 0
End If
Next
Thanks,
Jim Berglund