Lolo122298
11-05-2017, 05:41 PM
For my assignment, I have to create a macro that will find the highest value in a range along with the corresponding date. I created a macro but it only evaluates the first value in the range. How do I fix this?
Sub findhighestprice()
Dim maxprice As Currency
Dim maxdate As Date
Dim i As Integer
For i = 1 To 252
maxprice = Range("B2").Value
maxdate = Range("A2").Value
If Range("A2").Offset(i, 0) > Range("B2").Offset(i, 1) Then
maxprice = Range("B2").Offset(i, 1)
maxdate = Range("A2").Offset(i, 0)
End If
Next i
Range("s5").Value = maxprice
Range("s6").Value = maxdate
End Sub
Sub findhighestprice()
Dim maxprice As Currency
Dim maxdate As Date
Dim i As Integer
For i = 1 To 252
maxprice = Range("B2").Value
maxdate = Range("A2").Value
If Range("A2").Offset(i, 0) > Range("B2").Offset(i, 1) Then
maxprice = Range("B2").Offset(i, 1)
maxdate = Range("A2").Offset(i, 0)
End If
Next i
Range("s5").Value = maxprice
Range("s6").Value = maxdate
End Sub