fredrerik84
Active Member
- Joined
- Feb 26, 2017
- Messages
- 383
Hi guys I was lucky enough a few days ago to get help from Marcelo Branco
he helped me find max value at lightning speed with this code:
Sub aTest()
Dim lastRow As Long, vData As Variant, vResult As Variant
Dim i As Long
With Sheets("Sheet1")
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
vData = .Range("K12:U" & lastRow)
.Range("W12:Y" & lastRow).ClearContents
vResult = .Range("W12:Y" & lastRow)
For i = LBound(vData, 1) To UBound(vData, 1)
If vData(i, 1) <> "" Or vData(i, 5) <> "" Or vData(i, 9) <> "" Then
vResult(i, 1) = Application.Max(vData(i, 1), vData(i, 5), vData(i, 9))
vResult(i, 2) = Application.Max(vData(i, 2), vData(i, 6), vData(i, 10))
vResult(i, 3) = Application.Max(vData(i, 3), vData(i, 7), vData(i, 11))
End If
Next i
.Range("W12:Y" & lastRow) = vResult
End With
End Sub
Ive been editing this to suit my needs, but the problem im having is to find the target cell for the max value and also the target column for vResult 1-3
I was hoping anyone know a way to handle this ?
he helped me find max value at lightning speed with this code:
Sub aTest()
Dim lastRow As Long, vData As Variant, vResult As Variant
Dim i As Long
With Sheets("Sheet1")
lastRow = .Cells(.Rows.Count, "C").End(xlUp).Row
vData = .Range("K12:U" & lastRow)
.Range("W12:Y" & lastRow).ClearContents
vResult = .Range("W12:Y" & lastRow)
For i = LBound(vData, 1) To UBound(vData, 1)
If vData(i, 1) <> "" Or vData(i, 5) <> "" Or vData(i, 9) <> "" Then
vResult(i, 1) = Application.Max(vData(i, 1), vData(i, 5), vData(i, 9))
vResult(i, 2) = Application.Max(vData(i, 2), vData(i, 6), vData(i, 10))
vResult(i, 3) = Application.Max(vData(i, 3), vData(i, 7), vData(i, 11))
End If
Next i
.Range("W12:Y" & lastRow) = vResult
End With
End Sub
Ive been editing this to suit my needs, but the problem im having is to find the target cell for the max value and also the target column for vResult 1-3
I was hoping anyone know a way to handle this ?