在Excel中,如何检查两列是否重复?
我在Excel表格中有两列,
我想检查两列是否完全相同。 我的意思是说序列本身(Ax应该与Bx相同)。
例如,
AB
x1 x1
x2 x2
x3 x3
x4 y4
这里第4列应该高亮显示,因为x4和y4不一样。
谢谢
三个选项:
条件格式
如果你只是想突出差异,添加一个条件格式。
- 突出显示列A和B
- 添加条件格式高亮规则>更多规则
- 使用自定义公式
- = IF($ A1 <> $ B1,1,0)
- 添加填充格式以突出显示您的单元格
式
如果你想知道列A或B中的任何单元格是否不同,你
- 将公式= if(not(A1 = B1),1,0)添加到单元格C1
- 复制这个单元格并粘贴到C列
- 将公式= if(sum(C:C)> 0,'NOT EQUAL','EQUAL')添加到D1
- D1现在会告诉你列A = B
MACRO
添加一个macros,并用它做一些事情。 这个macros只是将结果粘贴到单元格E1中,并在运行时显示一个消息框。
Sub ColumnCheck() Dim i, LastRow, LastRowA, LastRowB, response 'get last row in column A and B, rather than 'iterating through all possible rows LastRowA = Range("A" & Rows.Count).End(xlUp).Row LastRowB = Range("A" & Rows.Count).End(xlUp).Row 'get the greatest row between A and B If LastRowA >= LastRowB Then LastRow = LastRowA Else LastRow = LastRowB End If 'iterate through all rows comparing them. For i = 1 To LastRow If Cells(i, "A").Value <> Cells(i, "B").Value Then response = "The columns are not equal!" Range("E1") = response MsgBox (response) Exit Sub End If Next response = "The columns are equal!" Range("E1") = response MsgBox (response)
结束小组
您也可以使用数组公式来查找两个单元格不匹配的第一行(如果有): –
=IFERROR("Difference in row "&MATCH(TRUE,A:A<>B:B,0),"No Difference")
(必须使用Ctrl Shift Enterinput )