匹配两个excel文档中的行

匹配两个excel文档中的行,excel,Excel,我正在处理excel中的两个大型csv文件(每个大约100-400 MB),其中一个需要拆分为两个文档(D1和D2),以便打开它。打电话给另一个D3。这些文档中除了标题之外的每一行都是表单ID、Data1、Data2、Data3。。。数据10左右,文件D1/2的数据与D3不同。我想将文档D1和D2中的信息添加到D3中,但只针对D3中存在的ID(一个较小的文件)。对我来说,最简单的方法是什么?如果我不需要在excel中打开文件,也可以使用D1/2文件 抱歉,如果这是一个令人困惑的问题,我可以在需要

我正在处理excel中的两个大型csv文件(每个大约100-400 MB),其中一个需要拆分为两个文档(D1和D2),以便打开它。打电话给另一个D3。这些文档中除了标题之外的每一行都是表单ID、Data1、Data2、Data3。。。数据10左右,文件D1/2的数据与D3不同。我想将文档D1和D2中的信息添加到D3中,但只针对D3中存在的ID(一个较小的文件)。对我来说,最简单的方法是什么?如果我不需要在excel中打开文件,也可以使用D1/2文件


抱歉,如果这是一个令人困惑的问题,我可以在需要时回答澄清问题

我这里有一些东西可以让您开始,请看一看并让我知道您的数据合并逻辑

Sub MergeData()

Dim D1 As Worksheet
Dim D3 As Worksheet
Dim Rng As Range
Dim Arr1 As Variant
Dim Arr2 As Variant
Dim Rw1 As Long, Rw2 As Long


'IF you the master file and 1 of the other files first in excel
'you can just reference them like this, otherwise change this accordingly
Set D1 = Workbooks("CSV1").Sheet1
Set D3 = Workbooks("CSV3").Sheet1


'D3 is the masterFile
'Lets store its data in Arr1
Set Rng = D3.UsedRange
Arr1 = Rng.Value

'since your working on large files lets try keep memory usage down to a minimum
'we will work on 2 sheets at a time not all 3.
'Arr2 now contains the sheet (CSV1) we will extract data from
Set Rng = D1.UsedRange
Set Arr2 = Rng.Value

Set Rng = Nothing

'Notice the + 1, its to skip the headers in case your wandering
'This is the basic loop setup
For Rw1 = LBound(Arr1, 1) + 1 To UBound(Arr1, 1)
    For Rw2 = LBound(Arr2, 1) + 1 To UBound(Arr2, 1)
        If Arr(Rw1, 1) = Arr2(Rw2, 1) Then  'OR  lcase(Arr(Rw1, 1)) = lcase(Arr2(Rw2, 1)) if letter case might be a problem
            'we found a matching ID
            'now im not sure exactly what you want to happen here.....
            'do you want to check if the master file has all the data that the other file has
            'if not then transfer the columns of data it is missing
            'or should all the columns in the master file be updated with the new values in the other file.....
            'This will change what code needs writing here
            'we may need an aditional array to hold new values temporarily
        End If
    Next Rw2
Next Rw1

'After all data has been extracted
'this code will also depend on what happens above
'but something like this
'set rng = D1.Range("this will be the size of the array").Value = Arr1
端接头

完全相同的代码将用于第二个文件,所以我只做了2个文件开始


我们需要更多关于提取哪些数据的输入,如果我们要替换主文件中的任何内容等,请具体说明。

请参阅。我不确定您的意思,我遵循了规则,通读了该部分,我相信我的问题相当简单。有什么地方让你感到困惑吗?你读过了,但你理解了吗??请再试一次。如果您对我的部分问题感到困惑,请说出来。更好的方法是将CSV导入数据库引擎(例如sql server express或mysql或任何最适合您的技能和需要的工具),并对D3执行更新查询(然后以您希望的方式导出数据)。Excel不是一个很好的数据库工具,大文件可能会导致问题,最大行数(引用MS)“1048576”(编辑),除此之外,它不是为大规模的“数据操作”而设计的(可能会导致稳定性损失和处理缓慢)