I have an Excel Sheet with values going in each column from cells 2:21
I need to highlight the corresponding cell in each column with the maximum value and try to loop through it with a macro. But I only know how to do it for a given hard-coded range..
Private Sub Worksheet_Activate()
Dim zelle As Range
For Each zelle In ActiveSheet.Range("B2:B21")
If zelle.Value = Application.WorksheetFunction.Max(Range("B2:B21")) Then
zelle.Interior.ColorIndex = 6
Else
zelle.Interior.ColorIndex = xlNone
End If
Next
End Sub
I tried to use a new range for column which I gave the Range (“B:IT”) and iterate through that one but that didnt work.
Maybe it’s just 2 or 3 lines?
This might work for you. Instead of using hard-coded ranges, it loops through whatever columns are used and adjusts for columns having different “lengths”. It assumes a single header row and column.