# Loop through rows in range

#### hughhuyton

##### New Member
I have this code that runs through each cell of a range and then highlights the highest value in yellow. How would I incorporate a loop to have it loop through each row of the range for it to highlight the maximum value in each row.

Code:
``````<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 'Helvetica Neue'; color: #454545; min-height: 14.0px}</style>Private Sub HighestValue()
Dim cell As Range

For Each cell In ActiveSheet.Range("A1:U1")
If cell.Value = Application.WorksheetFunction.Max(Range("A1:U1")) Then
cell.Interior.ColorIndex = 6
Else
cell.Interior.ColorIndex = xlNone
End If
Next
End Sub``````

### Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},\$Z\$1:\$Z\$99,\$Y\$1:\$Y\$99),2,False) to lookup Y values to left of Z values.

#### Tim_Excel_

##### Well-known Member
Code:
``````Sub HiLighter()
ActiveSheet.UsedRange
Dim rA As Range, r, wf As WorksheetFunction
Dim V As Variant, RWW As Range, rr As Range
Set rA = Intersect(Range("A:A"), ActiveSheet.UsedRange)
Set wf = Application.WorksheetFunction
For Each r In rA
Set RWW = Intersect(r.EntireRow, ActiveSheet.UsedRange)
If wf.CountA(RWW) = 0 Then Exit Sub
V = wf.Max(RWW)
For Each rr In RWW
If rr.Value = V Then
rr.Interior.ColorIndex = 6
GoTo getaway
End If
Next rr
getaway:
Next r
End Sub``````

Thanks to Excel VBA: Excel VBA: Find the maximum value in each row and highlight it - Stack Overflow

Just make sure you change the values to your liking

Last edited:

Replies
1
Views
99
Replies
20
Views
3K
Replies
2
Views
238
Replies
1
Views
210
Replies
4
Views
219

1,191,687
Messages
5,988,077
Members
440,125
Latest member
vincentchu2369

### We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.

### Which adblocker are you using?

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

### Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

### Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back