OK I've just looked at this properly... try the below (I've tried not to adjust from your existing code unless nec.)
Sub x()
Dim DstRng As Range
Dim R As Long
Dim RngEnd As Range
Dim rData As Range
Dim cell As Range
Dim dMin As Double
Dim dMax As Double
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
With Worksheets("INPUT")
'Set the first row of the destination
Set DstRng = .Range("A11:S11")
'Find any rows below the first that contain data
Set RngEnd = .Cells(Rows.Count, DstRng.Column).End(xlUp)
'Clear the cells
Set DstRng = IIf(RngEnd.Row < DstRng.Row, DstRng, .Range(DstRng, RngEnd))
DstRng.Clear
End With
With Worksheets("Details")
.UsedRange.Borders.LineStyle = xlNone
Set rData = .Range("R5:R604")
dMax = WorksheetFunction.Max(rData.Offset(, 1))
dMin = .Evaluate("MIN(IF(" & rData.Offset(, 1).Address & "=" & dMax & "," & rData.Address & "))")
For Each cell In rData
If cell.Offset(, 1).Value = dMax And cell.Value = dMin Then
With Intersect(.UsedRange, cell.EntireRow)
.BorderAround LineStyle:=xlContinuous, ColorIndex:=3, Weight:=xlMedium
.Copy
DstRng.Offset(R, 0).PasteSpecial xlPasteValues
R = R + 1
End With
End If
Next cell
Set rData = Nothing
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.CutCopyMode = False
End Sub
The key (IMO) is to establish the MIN for the MAX prior to commencing the Loop, this is done via the Evaluate.
Bookmarks