Do you mean replace
With Sheets("Result")
.Range("A4", "XFD1000000").ClearContents
If .Range("E1") < .Range("B1") Then .Range("E1") = .Range("B1")
with
With Sheets("Result")
Dim r As Range
Set r = ActiveSheet.UsedRange
Set r = r.Offset(3, 0)
r.ClearContents
If .Range("E1") < .Range("B1") Then .Range("E1") = .Range("B1")
I tried this and it seems to work...
Sub CPR()
Dim dat As Date, dat2 As Date, lr As Long, lc As Long, i As Long, j As Long, x As Long, arr As Variant, sn As Variant
Dim r As Range
Set r = ActiveSheet.UsedRange
Set r = r.Offset(3, 0)
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Sheets("Result")
r.ClearContents
If .Range("E1") < .Range("B1") Then .Range("E1") = .Range("B1")
dat = .Range("B1").Value
If .Range("E1") = "" Then
dat2 = dat
Else
dat2 = .Range("E1").Value
End If
End With
With Sheets("Totals")
lc = .Cells(3, .Columns.Count).End(xlToLeft).Column
For i = 1 To lc Step 5
lr = .Cells(Rows.Count, i).End(xlUp).Row
arr = .Range(.Cells(3, i), .Cells(lr, i + 4))
ReDim sn(1 To UBound(arr), 1 To UBound(arr, 2))
j = 0
For x = 3 To UBound(arr)
If arr(x, 1) >= dat And arr(x, 1) <= dat2 Then
j = j + 1
sn(j, 1) = arr(x, 1)
sn(j, 2) = arr(x, 2)
sn(j, 3) = arr(x, 3)
sn(j, 4) = arr(x, 4)
sn(j, 5) = arr(x, 5)
End If
Next
If j > 0 Then Sheets("Result").Cells(4, i).Resize(j, UBound(sn, 2)) = sn
Next
End With
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
Bookmarks