I am using the following code to loop through all rows in the designated columns in the ColourColumns array and color the cells depending on their value with a select case statement.
I would like to loop with 40 rows i 1 column F, then the next 40 rows in the same column and compare the values in the active column and find the min and the max value and perhaps rank the values from largest to smallest.
Then loop through the next 40 rows in the same column until the last row, then I want to loop through the next 40 rows in column G, then columns H, I, J, K, N, and M.
I would like help with how to compare the rows in batches of 40 and finding the max/min value out of the 40 rows that are being iterated at that time?
I would like to loop with 40 rows i 1 column F, then the next 40 rows in the same column and compare the values in the active column and find the min and the max value and perhaps rank the values from largest to smallest.
Then loop through the next 40 rows in the same column until the last row, then I want to loop through the next 40 rows in column G, then columns H, I, J, K, N, and M.
I would like help with how to compare the rows in batches of 40 and finding the max/min value out of the 40 rows that are being iterated at that time?
Code:
Public Sub ColourSomeCells()
Dim i As Long
Dim TotalRows As Long
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("PoängTest") 'define the worksheet
Dim ColourColumns As Variant
ColourColumns = Array("F", "G", "H", "I", "J", "K", "N", "M") 'columns you want to color
Dim LastRowInColumn As Long
Dim iRow As Long
Dim iCol As Variant
For Each iCol In ColourColumns 'loop through the array of columns
LastRowInColumn = ws.Cells(ws.Rows.Count, iCol).End(xlUp).Row 'find last used row in that column
For iRow = 2 To LastRowInColumn 'loop through all used cells in that column
With ws.Cells(iRow, iCol)
Select Case .Value
Case 0 'make zeros red
.Interior.Color = RGB(255, 199, 206)
Case 1, 2 'make zeros red
.Interior.Color = RGB(255, 199, 6)
Case 3, 4 'make zeros red
.Interior.Color = RGB(55, 99, 206)
Case 5, 6 'make zeros red
.Interior.Color = RGB(55, 99, 206)
Case 10, 11, 12 '
.Interior.Color = vbGreen
.Borders.Color = RGB(255, 255, 0)
Case Is > 20
.Interior.Color = vbBlue
Case Is > 30
.Interior.Color = RGB(185, 174, 165)
Case Is > 40
.Interior.Color = RGB(85, 174, 65)
Case Is > 50
.Interior.Color = RGB(185, 74, 165)
Case Else
End Select
End With
Next iRow 'next row in that column
Next iCol 'next column
End Sub