12/02/2013

Excel - Switching Row Foreground Color for each new value


This code permit to switch the text color each time a row have a different value.

Here the column considered for changement is the column "B"

cheers

 Sub test()  
   Dim currWCRFCode$  
   Call InitilizeColor  
   currWCRFCode = Range("B2").Value  
   For i = 2 To Range("B65536").End(xlUp).row  
     If (currWCRFCode <> Range("B" & i).Value) Then  
        Call incrementColorIndex  
     End If  
     Call setFont(i)  
     currWCRFCode = Range("B" & i).Value  
   Next i  
 End Sub  

 Private Sub setFont(ByVal row As Long)  
   Rows(row & ":" & row).Select  
    With Selection.Font  
     .color = getColor()  
     .TintAndShade = 0  
   End With  
 End Sub  

 Private Function getColor() As Long  
   getColor = colorsArray(currColorIndex)  
 End Function  

 Private Sub incrementColorIndex()  
   If (currColorIndex = 2) Then  
     currColorIndex = 0  
   Else  
     currColorIndex = currColorIndex + 1  
   End If  
 End Sub 
 
 Private Sub InitilizeColor()  
   currColorIndex = 0  
   colorsArray(0) = RGB(0, 0, 0)  
   colorsArray(1) = RGB(152, 14, 138)  
   colorsArray(2) = RGB(28, 152, 14)  
 End Sub  

1 comment:

  1. The photos, numbers, or letters gamers see in a slot machine are what’s identified as|often recognized as} symbols. Common symbols utilized in slot machines are fruits, bells, 7’s, and bars, among others. Players win based mostly on what number of} of those symbols could be matched on a payline. Those winlines pay the player based mostly on their guess per line they guess on i.e. A player could be on a single line to win or 25 strains to win 메리트카지노 at varying amounts per line.

    ReplyDelete