Search : in
By :

Coloring the header row based on the cell col

Last answer on Jan 20, 2009 1:14:12 pm GMT rajaid, on Jan 20, 2009 9:40:37 am GMT 
 Report this message to moderators

Hello,

I had a report, which needs to be colored based on the average value of cells. For eg if the cell value is less than 0.2 Avg, they should be red color,if value is between 0.2 and 0.5 it should be yellow

Now based on the color of the rows cells , the header row needs to be colored. Logic is Coloum header should be in red colour, if in one or more number of rows cells are red. same with yellow ones.

For the first part, i colored the cells with conditional formatting, for second one i wrote a macro code. But some how the header row is not getting color as expected, even though the color index used in conditional formatting and code are similar. I am pasting the code .

ActiveCell.FormulaR1C1 = "=AVERAGE(RC[-7]:RC[-1])"
    Range("L13").Select
    Selection.AutoFill Destination:=Range("L13:L144")
    Range("L13:L144").Select
    Columns("L:L").Select
    Selection.NumberFormat = "0"
    Range("E13:K144").Select
    Selection.FormatConditions.Delete
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlBetween, _
        Formula1:="=$L13 * 0,2", Formula2:="=$L13 * 0,5"
    Selection.FormatConditions(1).Interior.ColorIndex = 6
    
    Dim R As Integer
    Dim Y As Integer
    
    For Each C In Range("K13:K144")
    If C.Interior.ColorIndex = 3 Then R = R + 1
    If C.Interior.ColorIndex = 6 Then Y = Y + 1
    
    Next C
    
    If R > 0 Then
    Range("K11").Interior.ColorIndex = 3
    ElseIf Y > 0 Then
    Range("K11").Interior.ColorIndex = 6
    Else
    Range("K11").Interior.ColorIndex = 4
    End If
    
        R = 0: Y = 0:
        
         For Each C In Range("E13:E144")
    If C.Interior.ColorIndex = 3 Then R = R + 1
    If C.Interior.ColorIndex = 6 Then Y = Y + 1
    
    Next C
    
    If R > 0 Then
    Range("E11").Interior.ColorIndex = 3
    ElseIf Y > 0 Then
    Range("E11").Interior.ColorIndex = 6
    Else
    Range("E11").Interior.ColorIndex = 4
    End If
    
        R = 0: Y = 0:



Could you please help me in solving this. Also, Instead of coloring of cells based on conditional formatting, i thought of doing it through VB code, but i have no idea of doing that.

Please advise.

Thanks & Regards,
Raj
Configuration: Windows XP
Internet Explorer 7.0

Best answers for « Coloring the header row based on the cell col » in :
VB6 Finding the RGB values of a color ShowVB6 Finding the RGB values of a color Dim R as integer Dim G as integer Dim B as integer Sub FindRGB(Col As Long) R = &HFF& And Col G = (&HFF00& And Col ) \ 256 B = (&HFF0000 And Col ) \ 65536 End Sub Note: Here...
Basic Excel Formulas ShowBasic Excel Formulas Below are some basic formulas for Microsoft excel: Basic formula : ADDITION cell A1 to A10 = sum (A1: A10) AVERAGE cell A1 to A10 = average (A1: A10) MAXIMUM cell A1 to A10 = max (A1: A10) MINIMUM...
Colouring cells on conditions ShowColouring cells on conditions There are many pratical functions under Excel which is not commonly used. Example: If you wish a cell automatically turns red (or other formatting border, frame etc) under one condition: a result, a...
Spreadsheets - Cell Selection ShowCell Selection Spreadsheets are powerful tools for working with data. However, to work with data, it is necessary to have tools to rapidly choose the required cells. Line Selection An entire line can be chosen by clicking directly on the line...
Worksheet - Cells ShowThe Concept of a Cell A "cell" is the intersection between a line (horizontal) and a column (vertical) on a worksheet. Thus, the name of the line combined with the name of the column gives the cell's coordinates (the term address is sometimes also...
Spreadsheet - Formulas ShowIntroduction to Formulas The main use of a spreadsheet is to automate calculations, which means using cells to perform operations based on values in other cells. The spreadsheet recalculates all the values each time a change is made to the value of...

1

 eurospc, on Jan 20, 2009 1:14:12 pm GMT

Hi,
try this link,you will get help about conditional formatting:
http://www.contextures.com/xlCondFormat02.html

Reply to eurospc