这里似乎存在三个问题:
1) 查找两个文件之间的匹配记录(第一列)。
2)比较第一列匹配的记录——如果有差异,记录差异是什么
3)如果记录存在于一个文件中但不存在于另一个文件中,则记录该文件。
我将假设这两个“巨大的文件”实际上是同一个 Excel 工作簿中的单独工作表,并且记录按第一个键排序。这将显着加快处理速度。但我认为,速度是次要问题。我还假设有第三张表用于放置输出。
这是 VBA 代码的大纲 - 您必须做一些工作才能使其“恰到好处”适合您的应用程序,但我希望这能让您继续前进。
Sub compare()
Dim s1 as Worksheet
Dim s2 as Worksheet
Dim col1 as Range
Dim col2 as Range
Dim c as Range
Dim record1 As Range, record2 As Range, output As Range
Dim m
Dim numCols as Integer
numCols = 5 ' however many columns you want to compare over
Set s1 = Sheets("Media")
Set s2 = Sheets("Pro")
Set output = Sheets("output").Range("A2")
Application.ScreenUpdating = False
s1.Select
Set col1 = Range("A2", [A2].End(xlDown));
s2.Select
Set col2 = Range("A2", [A2].End(xlDown));
On Error Resume Next
For Each c in col1.Cells
m = Application.Match(c.Value, col2, 0);
If isError(m) Then
' you found a record in 1 but not 2
' record this in your output sheet
output.Value = "Record " & c.Value & " does not exist in Pro"
Set output = output.Offset(1,0) ' next time you write output it will be in the next line
' you will have to do the same thing in the other direction - test all values
' in 2 against 1 to see if any records exist in 2 that don't exist in 1
Else
' you found matching records
Set record1 = Range(c, c.offset(0, numCols))
Set record2 = Range(col2.Cells(m,1), col2.Cells(m,numCols))
' now you call another function to compare these records and record the result
' using the same trick as above to "go to the next line" - using output.Offset(1,0)
End If
Next c
End Sub