Excel Conditional Formatting 3-color over one row

2020-06-09 07:19发布

问题:

I've got some excel spreadsheets with a couple hundred to couple thousand rows. Each row represents a set of measurements taken at one second intervals.

I want to use the 3 color conditional formatting for each row. I can setup a single row for the 3 color by setting the "Applies to" to something like:

 'Table1'!$B$2:$M$2

However, if i try to copy the format and then apply it to multiple rows, (say B3:M400), it will treat the entire block (all cells from B3 through M400) as a single conditional format, so each cell is colored according to all of the other cells. What i'm looking for is a way to apply the 3 color conditional formatting to each row individually over many many rows.

For example, in the image linked here: http://electriceptor.files.wordpress.com/2012/04/screen-shot-2012-04-30-at-11-53-36-pm.png (sorry, i'm too new to post images), each of the rows has an individual 3 color format that i manually applied to each row.

However, if i copy a single row and paste the format into that same block of 7 rows, it looks like this image: http://electriceptor.files.wordpress.com/2012/04/screen-shot-2012-04-30-at-11-56-42-pm.png:

Note how the formatting is applied to the entire block.

Is there a way to apply the conditional formatting for each row individually without doing each row manually?

回答1:

Since 3-color conditional formatting doesn't accept relative references (no matter how much you try to 'trick' Excel with INDIRECT, ADDRESS, etc.), your best bet is to use the method here (example was for 2-color formatting): https://superuser.com/questions/350378/excel-2007-conditional-formatting-so-that-each-row-shows-low-values-yellow-hig

This is the same as using the format painter on each individual row (using the format painter on multiple rows puts you back to square one where it looks at all the rows).

Sub NewCF()
    Range("B1:M1").Copy
    For Each r In Selection.Rows
    r.PasteSpecial (xlPasteFormats)
Next r
Application.CutCopyMode = False
End Sub

Also, there's no limit to the number of conditional formatting rules (at least in Excel 2010), but the more you have, the more potential there is for a negative impact on performance. You'll just have to try it and see. In the worst-case scenario, I would make 3-10 (or however many you can stand to make) individual rules based on a formula to create a "gradient", but this may be just as cpu-intensive.



回答2:

I've just tried using the fill handle on a cell with conditional formatting e.g. =COUNTIF(C2,"Yes")=1 then applies to $A2 and then selected that cell and dragged the fill handle - it adds the conditional formatting to each row automatically! jippee!