+ Reply to Thread
Results 1 to 5 of 5

Coloring cell based on condition

  1. #1
    Registered User
    Join Date
    01-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8

    Coloring cell based on condition

    Hi,

    I had an report and the rows of the report needs to be colored based on another cell value.

    My layout looks like this :

    A1 B1 C1 D1 AVG
    10 11 12 13 30
    14 15 16 17 100
    18 19 20 21 400

    For each cell, i need to compare the value of cell with that value in AVG coloumn and if condition is met, cell should be colored.

    Eg : If first cell value under A1 is Less than 0.2 * AVG of first row then color of the cell A2 should be red.

    After coloring the entire rows, then i should check and color the header row based on the color of Rows.

    I tried first one, i,e coloring the rows based on conditional formatting and then written VB code to compare the color of rows and colored the header row. But the color index used in conditional formatting and the code are mismatching and the desired output is not coming.So decided to write code for coloring the rows cell.

    Could you please provide sample coding as how to color of Rows based on the condition, i.e reading each cell with that AVG coloumn.

    Thanks & Regards,
    Raj
    Last edited by rajaid; 01-27-2009 at 09:06 AM.

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387
    rajaid,

    Please see the attached workbook "Conditional Formatting - Coloring cell based on condition - rajaid - SDG.xls".

    There are instructions for applying Conditional Formatting for your worksheet.

    And, run the "UpdateTable" macro.


    Please attach a copy of YOUR workbook so that I can try to automate the execution of the macro.


    Have a great day,
    Stan
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    01-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8
    Hi,

    We can acheive this through conditional formatting. But, i need the same logic in Vb code as how to color the cell based on the multiplication of another cell.

    could you please provide logic as how to solve this problem.

    Thanks & Regards,
    Raj

  4. #4
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387
    Raj,

    Please post your workbook - scroll down and see "Manage Attachments".


    Have a great day,
    Stan

  5. #5
    Registered User
    Join Date
    01-15-2009
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    8
    Hi,

    i attached my work book. i want to color the rows based on the Avg coloum through VB coding .

    through conditional formatting, i am able to color the rows, but based on the rows i should color the date coloumn also and that is not working if i color the rows cells through conditional formatting.

    For eg : if any of the rows cell is yellow, the corresponding date coloumn should also be yellow.

    i have written vb code for coloring the rows cell based on Avg coloum, but it is not working as expected.I am attaching the sample coding.

    Please Login or Register  to view this content.
    [ For Each Cell In Range("B2:H12")
    If Cell.Value < "$I2 * 0.2" Then
    Cell.Interior.ColorIndex = 3

    ElseIf (Cell.Value > "$I2 * 0.2") and (Cell.Value < "$I2 * 0.5")Then
    Cell.Interior.ColorIndex = 6
    Else
    Cell.Interior.ColorIndex = xlNone
    End If

    Next ]

    Please advise where exactly the problem lies.

    Thanks & Regards,
    Raj
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1