识别列之间的所有常见行

我有一个电子表格,其中包含许多列,我想确定在所有列中通用的所有行。 无论是通过突出显示还是创build另一列,我都没有偏好。 同样,公式或macros也同样可以接受。

举个例子,

 --------------------------------------
 | 清单1 | 列表2 | 清单3 | 清单4 |
 --------------------------------------
 | 比尔| 卡洛斯| 亚当| 亚当|
 | 卡洛斯| 丹| 比尔| 卡洛斯|
 | 弗兰克| 弗兰克| 卡洛斯| 弗兰克|
 |  | 杰拉德| 弗兰克| 利亚姆|
 |  |  | 吉姆|  |
 --------------------------------------

在上面的例子中,我想确定卡洛斯和弗兰克在所有专栏中都很常见。

注意所有的列都是sorting和唯一的。

我目前通过一个macros来组织这些项目,并将它们在列上alignment。 我从这一点上可以很容易地使用条件格式来突出显示所有空白行,但是无法完成这一点。 也许我是以错误的方式去做的。

macros代码:

Option Explicit Sub LineEmUp() 'Author: Jerry Beaucaire 'Date: 7/5/2010 'Summary: Line up a random number of columns so all matching ' items are on the same rows Dim LC As Long Dim Col As Long Dim LR As Long Application.ScreenUpdating = False 'Spot last column of data LC = Cells(1, Columns.Count).End(xlToLeft).Column 'Add new key column to collect unique values Cells(1, LC + 1) = "Key" For Col = 1 To LC Range(Cells(2, Col), Cells(Rows.Count, Col)).SpecialCells(xlConstants).Copy _ Cells(Rows.Count, LC + 1).End(xlUp).Offset(1) Next Col Columns(LC + 1).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Cells(1, LC + 2), Unique:=True Columns(LC + 2).Sort Key1:=Cells(2, LC + 2), Order1:=xlAscending, Header:=xlYes 'Fill in new table headers w/formatting Range("A1", Cells(1, LC)).Copy Cells(1, LC + 3) 'Fill in new table values LR = Cells(Rows.Count, LC + 2).End(xlUp).Row With Range(Cells(2, LC + 3), Cells(LR, LC + 2 + LC)) .FormulaR1C1 = "=IF(ISNUMBER(MATCH(RC" & LC + 2 & ",C[-" & LC + 2 _ & "],0)), RC" & LC + 2 & ", """")" .Value = .Value End With 'Cleanup/Erase old values Range("A1", Cells(1, LC + 2)).EntireColumn.Delete xlShiftToLeft Columns.Autofit Application.ScreenUpdating = True End Sub 

您可以使用数组公式(input时使用Ctrl + Shift + Enter)

在这里输入图像说明

我在这里使用了列C,但是select哪一列来从中提取值并不重要。

如图所示,条件格式也将起作用:使用基于公式的规则

 =COUNTIF($A$2:$D$6,A2)=COLUMNS($A$2:$D$6) 

要应用,请select整个数据集(不包括标题),并确保A2是Activecell。

如果你想检查list1是否在list2内任何地方,你需要把*通配符放在它的每一边,像这样:

 =If(Iserror(Match("*"&B1&"*",A:A,0)),"False","True") 

用整个文件的名称作为内容构build一个string数组。 然后遍历每个名​​称的数组,并计算它发生的次数。 由于名称只能在每列中出现一次,因此您可以使用它们在数组中的出现来判断它是否包含在所有列中。

如果名称与文件中的列一样多,则知道它包含在所有列中。

希望这会让你开始!