3

这是我第一次在这里发帖,但我不知道还能去哪里。

我在excel中有两个列表,它们都有相似的数据但顺序不同,每个列表都有3列(前缀(A,D),后缀(B,E)和数据(C,F))。

假设列表 1 在 A、B 和 C 列中;并在 D、E、F 中列出 2。

C 列中的每个元素在 F 列中都有一个相同的元素,但顺序不同,而且前两列(前缀和后缀)可能具有或不具有与其对应项不同的值。

我想这样做(我想它必须用宏来完成,但我真的不知道,我不是 excel 专家),我想从 C 列(数据)中获取每个元素并找到它在F列中是等价的,在那之后,我想比较它们的前缀和后缀,当它们不同时可能将其涂成红色,当它们相同时将其涂成绿色。

这可能吗?(并没有太多的麻烦?)

如果您有不明白的地方,请回复,我很乐意尝试更好地解释。

4

2 回答 2

3

You can do it without macros by using conditional formatting

(There is an excellent write up of conditional formatting at Debra Dalgleish's site here. In xl2003 conditional formatting is accessed via the Format .. Conditional Formatting menu.)

If your data to be matched was in A1:F10 then these two formulas can be used to

  • match column C against F and return the position in F where column C has a match
  • compare the values in column D and E in this position to the respective values in columns A and B
  • format column A and B for valid matches using =A1=INDEX(D$1:D$10,MATCH($C1,$F$1:$F$10,0))
  • format column A and B for invalid matches using =A1<>INDEX(D$1:D$10,MATCH($C1,$F$1:$F$10,0))

In the sample below I have added these two conditional formats to cells A1:B10 in xl2010

A valid match is green Invalid matches are red Non matches are not formatted

So A1 and B1 are green as they match D2 (Mr) and E2 (Jones) for a common value of 1 in C1 and F2
So A3 is green as it matches D1 (Father) for 10 in C3 and F1, but B3 is red as E1 does not contain "wang"

enter image description here

于 2012-02-26T04:31:21.797 回答
1

我会做以下事情:

  1. 将 F 列移到 D 和 E 列之前(现在 D 是数据,E 是前缀,F 是后缀)

  2. 使用公式创建三个新列 G、H 和 I:

    =vlookup(C1, D:F, 2, 0)

    =vlookup(C1, D:F, 3, 0)

    =and(G1=A1,H1=B1)

  3. 将条件格式放在 I 列上,红色表示 FALSE,绿色表示 TRUE。

The first step is necessary because VLOOKUP will look for the value in the first column of data.

On the second step, you will match the column C with column F (now moved to D) and obtain the corresponding prefix and suffixes. The next formula compares both and returns TRUE or FALSE if they both match.

You could combine all three formulas in one, if needed.

于 2012-02-26T04:31:10.650 回答