Looping through the first 15 values of a Range
I am trying to paint the first 15 values that met certain condition, but with this code I am painting the first column in the first 15 values without taking into account if the condition is met and the rest of the cells in the second column.
When cell 2,20 is higher than 15, I need to paint the first 15 values that met the condition "Crearte" in the first column and the rest in the second column.
g and h are numbers.
For i = g + 1 To g + h If Cells(2, 20) <= 15 And Cells(i, 5) = "Crearte" Then Cells(i, 5).Interior.Color = 255 Else Cells(i, 5).Interior.Color = 16777215 End If If Cells(2, 20) > 15 And Cells(i, 5) = "Crearte" Then For j = g + 1 To g + 15 Cells(j, 5).Interior.Color = 255 Next For j = g + 16 To g + h Cells(j, 6).Interior.Color = 255 Next End If Next