我有两个excel文件,每个文件有1553行和40列。它们具有相同的列名,应该相同。但似乎存在一些差异。我想知道是否有一些代码可以检测并突出显示/汇总(哪一行/列)不同的单元格。
答案 0 :(得分:2)
有两种方法可以做到这一点
IF(cell1=cell2,"","Not Matching")
答案 1 :(得分:0)
Excel有一个加载项,用于比较名为"查询"的文件。可能值得一试。请注意,有版本要求。
答案 2 :(得分:0)
我刚刚编写了这段代码来查找不匹配的单元格并为您突出显示每个单元格。您需要使用适当的工作表名称更改Sheet1和Sheet2,然后确保行和列计数以正确的数字开头和结尾。希望有所帮助!
Sub comparison()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim CellValuews1 As Variant
Dim CellValuews2 As Variant
Dim ErrorCount As Integer
Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
ErrorCount = 0
For I = 1 To 40
For X = 1 To 1553
CellValuews1 = ws1.Cells(X, I).Value
CellValuews2 = ws2.Cells(X, I).Value
If CellValuews1 = CellValuews2 Then
Else
ws1.Cells(X, I).Interior.ColorIndex = 6
ws2.Cells(X, I).Interior.ColorIndex = 6
ErrorCount = ErrorCount + 1
End If
Next
Next
MsgBox "There were " & ErrorCount & " Cells that didn't match. These are now highlighted yellow"
End Sub