Excel - Shading entire row based on change of value

后端 未结 11 1672
一生所求
一生所求 2020-12-23 20:05

I would like to shade entire rows in Excel based on the value of one cell. For example say I have the rows below:

**File No**
1122
1122
1144
1155
1155
1155
         


        
相关标签:
11条回答
  • 2020-12-23 20:12

    If you are using MS Excel 2007, you could use the conditional formatting on the Home tab as shown in the screenshot below. You could either use the color scales default option as I have done here or you can go ahead and create a new rule based on your data set. Conditional Formatting

    0 讨论(0)
  • 2020-12-23 20:13

    I had to do something similar for my users, with a small variant that they want to have a running number grouping the similar items. Thought I'd share it here.

    • Make a new column A
    • Assuming the first row of data is in row 2 (row 1 being header), put 1 in A2
    • Assuming your File No is in column B, in the second row (in this case A3) make the formula =IF(B3=B2,A2,A2+1)
    • Fill/copy-paste cell A3 down the column to the last row (be careful not to copy A2 by accident; that will populate all cells with 1)
    • Select the data range
    • In the Home ribbon select Conditional Formatting -> New Rule
    • Choose Use a formula to determine which cells to format
    • In the formula cell, put =MOD($A1, 2)=1 as the formula
    • Click Format, select the Fill tab
    • Select the Background Color you want, then click OK
    • Click OK

    enter image description here

    0 讨论(0)
  • 2020-12-23 20:14
    A simpler version of one of the above answers. Column A is the key.
    Yes, it needs a helper column.  That's column K.
    1) Set first cell in table to TRUE (K8)
    2) On second row at K9, and to end of table (K99), paste: =IF(A8=A9,K8,NOT(K8))
    This gives a pattern of TRUE...TRUE, FALSE...FALSE,...
    3) Select key column A1:A99, or whole table A1:K99
    4) Set Home/Conditional/New Rule/Formula  =K8
    5) Format as you wish for the TRUE cells
    6) Select the range from (3) and Right-click Format White (or whatever
    background color you want) for the FALSE cells
    
    Note that this solution (and the others) have a major flaw, in that this
    highlighting doesn't work properly when you have filters active in your
    table.  I want that fix :)
    
    0 讨论(0)
  • 2020-12-23 20:15

    I have found a simple solution to banding by content at Pearson Software Consulting: Let's say the header is from A1 to B1, table data is from A2 to B5, the controling cell is in the A column

    1. Make a new column, C
    2. At first the first row to color make the formula =true in the C2 cell
    3. In the second row make the formula =IF(A3=A2,C2,NOT(C2))
    4. Fill the column down to the last row
    5. Select the data range
    6. Select conditional formatting, choose Use a formula... and put =$C2 as the formula
    0 讨论(0)
  • 2020-12-23 20:18

    In MS Excel, first save your workbook as a Macro Enabled file then go to the Developper Tab and click on Visual Basic. Copy and paste this code in the "ThisWorkbook" Excel Objects. Replace the 2 values of G = and C= by the number of the column containing the values being referenced.

    In your case, if the number of the column named "File No" is the first column (namely column 1), replace G=6 by G=1 and C=6 by C-1. Finally click on Macro, Select and Run it. Voila! Works like a charm.

    Sub color()
        Dim g As Long
        Dim c As Integer
        Dim colorIt As Boolean
    
        g = 6
        c = 6
        colorIt = True
    
        Do While Cells(g, c) <> ""
            test_value = Cells(g, c)
            Do While Cells(g, c) = test_value
                If colorIt Then
                    Cells(g, c).EntireRow.Select
                    Selection.Interior.ColorIndex = 15
                Else
                    Cells(g, c).EntireRow.Select
                    Selection.Interior.ColorIndex = x1None
                End If
                g = g + 1
            Loop
            colorIt = Not (colorIt)
        Loop
    End Sub
    
    0 讨论(0)
  • 2020-12-23 20:20

    Use Conditional Formatting.

    In it's simplest form, you are saying "for this cell, if it's value is X, then apply format foo". However, if you use the "formula" method, you can select the whole row, enter the formula and associated format, then use copy and paste (formats only) for the rest of the table.

    You're limited to only 3 rules in Excel 2003 or older so you might want to define a pattern for the colours rather than using raw values. Something like this should work though:

    alt text

    0 讨论(0)
提交回复
热议问题