Mel Smith
Well-known Member
- Joined
- Dec 13, 2005
- Messages
- 1,041
- Office Version
- 365
- Platform
- Windows
I'm using the following code to highlight the maximum value in a range but it keeps failing at the "maxVal = cell.Value" line:
The maximum value in this case is 120.90.
Can someone point me in the right direction, please?
Mel
VBA Code:
Sub Strike_Rate()
Dim rng As Range
Dim cell As Range
Dim maxVal As Double
Set rng = Range("DI4:DI33") ' Change this to your desired range
maxVal = rng.Cells(1).Value
For Each cell In rng
If cell.Value > maxVal Then
maxVal = cell.Value
End If
Next cell
For Each cell In rng
If cell.Value = maxVal Then
cell.Interior.Color = RGB(255, 255, 0) ' Highlight in red; you can change the color as desired
End If
Next cell
End Sub
The maximum value in this case is 120.90.
Can someone point me in the right direction, please?
Mel