比较两个Excel表

我如何比较两个Excel表并确定哪一列丢失?

(我想比较表A中的国家名单和表B,然后标记哪个国家丢失)

注:他们是随机的顺序。

您可以在Excel工作表中使用VLOOKUP函数来帮助查找其他工作表中的“缺失”数据。 例如,采取以下两个工作表:

 Sheet1 ------ ABC 1 aa 2 bb 3 cc 4 dd 

 Sheet2 ------ ABC 1 aa 2 bb 3 dd 

将下面的公式添加到Sheet单元格B1 ,然后将公式向下拖动到单元格B4

 =IF(ISERROR(VLOOKUP(A1,Sheet2!$A$1:$A$3,1,FALSE)),"MISSING FROM OTHER SHEET","") 

Sheet1应该指出B列中另一张纸上缺less的项目,如下所示:

 Sheet1 ------ ABC 1 aa 2 bb 3 cc MISSING FROM OTHER SHEET 4 dd 

您可以使用Excel的ADO

 Dim cn As Object Dim rs As Object Dim strFile As String Dim strCon As String Dim strSQL As String Dim s As String Dim i As Integer, j As Integer ''This is not the best way to refer to the workbook ''you want, but it is very conveient for notes ''It is probably best to use the name of the workbook. strFile = ActiveWorkbook.FullName ''Note that if HDR=No, F1,F2 etc are used for column names, ''if HDR=Yes, the names in the first row of the range ''can be used. ''This is the Jet 4 connection string, you can get more ''here : http://www.connectionstrings.com/excel strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile _ & ";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";" ''Late binding, so no reference is needed Set cn = CreateObject("ADODB.Connection") Set rs = CreateObject("ADODB.Recordset") cn.Open strCon ''Query example: strSQL = "SELECT Country " _ & "FROM [Sheet1$] a " _ & "WHERE Country NOT IN " _ & "SELECT Country FROM [Sheet2$]" ''Open the recordset for more processing ''Cursor Type: 3, adOpenStatic ''Lock Type: 3, adLockOptimistic ''Not everything can be done with every cirsor type and ''lock type. See http://www.w3schools.com/ado/met_rs_open.asp rs.Open strSQL, cn, 3, 3 If rs.Count>0 Then MsgBox rs.GetString End If 

也可以使用CopyFromRecordset将logging集快速写入表单。

解决scheme取决于所涉及的行数以及您需要执行此操作的次数,以及希望如何显示信息。

如果你没有很多的国家,你只需要做一次,最快的解决scheme是:

  • 将这两个列都复制到临时表单中。
  • 按字母顺序排列两列。
  • 手动通过他们,发现差异。

如果你只需要这样做一次,但有很多国家,vlookup选项是最快的。

如果需要多次重复此过程,并且需要在某处使用该列表(即在其他表单中),则可以使用更复杂的解决scheme,其中包括两个带查找的附加列和透视表。 但是在那个时候,我会考虑把它移动到更易于pipe理的地方,就像一个小型的数据库。

我使用以下独家软件。
[Excel差异 – http://www.suntrap-systems.com/ExcelDiff/%5D

还有其他的软件下面的网站。
[http://www.softpedia.com/]

我发现,在某些版本的Excel中是比较文件的function – 但通常被禁用,但无论如何。 有一天我偶然发现如何使用它。

如果你已经安装了TortoiseSVN(真的): – 在文件pipe理器中selectexcel文件进​​行比较 – 打开上下文菜单,然后selectTortoiseSVN> Diff – 在“比较模式”下打开excel,