简体   繁体   English

将条件格式复制到其他行

[英]Copy conditional formatting to other rows

I have a list of items, each with its own code, that I would like the user to rank in an arbitrary order of preference 1st to 5th. 我有一个项目列表,每个项目都有自己的代码,我希望用户以第1到第5的任意优先级进行排名。 Not all items need to be ranked. 并非所有项目都需要排名。 However, each item should only be ranked ONCE (no duplicates). 但是,每个项目只能一次排名(没有重复项)。 My sample table of records is as follows: 我的记录样本表如下:

ID  1st 2nd 3rd 4th 5th

1   U74 L65 G56 N28 M82

2   N28 A11 L65 P37 L65

3   H72 R99 B42 Y95 G56

4   T63 C58 P37 B42 C58

(In this instance, user ID 2 and 4 have duplicate codes L65 and C58 respectively) (在这种情况下,用户标识2和4分别具有重复的代码L65和C58)

Checking and highlighting duplicate codes in a single row is easily done with conditional formatting. 使用条件格式可以轻松地检查并突出显示单行中的重复代码。 The problem I'm running into is how to "copy" the formatting to the rest of the rows. 我遇到的问题是如何将格式“复制”到其余行。 My actual dataset has over 300 records, so doing it manually for each row is not really an option. 我的实际数据集有300多个记录,因此手动对每一行进行记录并不是一种选择。

If you have a data like this: 如果您有这样的数据:

在此处输入图片说明

You just need to use this formula: =COUNTIF($B2:$F2,B2)>1 您只需要使用以下公式: =COUNTIF($B2:$F2,B2)>1
Of course you need to use Use a formula to determine which cell to format as a rule type: 当然,您需要使用“ Use a formula to determine which cell to format为规则类型:

在此处输入图片说明

And also you need to define where you'll apply the formatting ( $B$2:$F$5 in our example). 另外,您还需要定义格式的应用位置(在我们的示例中$B$2:$F$5 )。
Or you can select the entire range you want to format before actually adding the Conditional Format 或者,您可以在实际添加条件格式之前选择要格式化的整个范围

在此处输入图片说明

The result would be: 结果将是:

在此处输入图片说明

Is this what you're trying? 这是您要尝试的吗?

Edit1: How it works? Edit1:它是如何工作的? (for zipzit) (对于zipzit)

Let us examine the formula: =COUNTIF($B2:$F2,B2)>1 让我们检查一下公式: =COUNTIF($B2:$F2,B2)>1
Which we applied in: $B$2:$F$5 我们在其中应用: $B$2:$F$5

Regular formula in Excel Cells behaves the same way when used in Conditional Formatting . 条件格式中使用时,Excel单元格中的常规公式的行为方式相同。
So absolute and relative cell address (with $ and without $ ) applies to it as well. 因此,绝对和相对单元地址(带有$和不带有$ )也适用于它。
So if we apply the formula for example in B2 only, it will evaluate how many occurrence does the value in B2 have in $B2:$F2 using COUNTIF formula. 因此,如果仅在B2应用公式,它将使用COUNTIF公式来评估B2中的值在$B2:$F2出现了多少次。

The answer is 1. In our formula, you'll only format it if it is >1 . 答案是1。在我们的公式中,仅当它>1 ,才对其设置格式。
Now say we copy it in C2 . 现在说我们将其复制到C2
Notice that B2 in our formula use relative referencing both on rows and column. 注意,我们公式中的B2在行和列上都使用了相对引用。
So instead of evaluating B2 again against $B2:$F2 , it will evaluate C2 . 因此,它将不再对$B2:$F2评估B2 ,而是对C2进行评估。
Now, to make sure it will evaluate it against the same set of range $B2:$F2 , notice that we precede the column address with $ . 现在,要确保它将针对同一范围的范围$B2:$F2进行评估,请注意,我们在列地址之前添加了$

I have other post about Conditional Formatting which you might want to check out. 我还有其他关于条件格式的文章 ,您可能想看看。

在此处输入图片说明

Ouch, you are right. 哎呀,你是对的。 There appears to be no easy way to copy the format to more than one row at a time. 似乎没有一种简单的方法可以一次将格式复制到多个行中。 I've tried many different versions of the F4 trick, to no avail. 我尝试了许多不同版本的F4技巧,但无济于事。

You're not going to like this answer, but I'd do it via macro, copy all the data to a new sheet tab, count the number of rows, then loop from top to bottom using a row pointer and paste "format only" one line at a time via the macro. 您不会喜欢这个答案,但我会通过宏进行操作,将所有数据复制到新的工作表标签中,计算行数,然后使用行指针从上到下循环并粘贴“仅格式”通过宏每次一次一行。 Its not romantic, but it will work. 它不是浪漫的,但是会起作用的。

Another way to do it is to trick the code so you can do a math review (eg 另一种方法是欺骗代码,以便您可以进行数学复习(例如
vote #1 = 00000001 (U74) vote #00000010 (L65) vote #00000100 (G56) vote#00001000 (N28) vote#00010000 (M82) ... etc... 投票#1 = 00000001(U74)投票#00000010(L65)投票#00000100(G56)投票#00001000(N28)投票#00010000(M82)...等...

that way you'd just add the votes, and you should see 01011101 for a result. 这样,您只需添加投票,结果01011101 If you see 10021100 you immediately know there is a repeat. 如果看到10021100您将立即知道有重复。 Not sure how many choices your folks have to vote for... You could actually do this with binary numbers (expressed as digital #'s then use Dec2Bin conversion on the sum to quickly see the result) 不知道您的人必须投票多少选择...您实际上可以使用二进制数字来完成此操作(表示为数字#,然后对总和使用Dec2Bin转换以快速查看结果)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM