2016-04-15 13 views
0

Excelで2つの大きなcsvファイル(それぞれ100-400 MB程度)を処理していますが、そのうちの1つを開くには2つの文書(D1とD2)に分割する必要があります。もう1つはD3と呼んでください。これらの文書の各行は、ID、Data1、Data2、Data3 ...の形式のヘッダー以外の各行にあります。D3とは異なるデータを持つ文書D1/2を持つデータ10程度です。ドキュメントD1とD2の情報をD3に追加したいが、D3にあるID(小さいファイル)についてのみ情報を追加したい。これを行うための最も簡単な方法は何ですか?もし私がExcelでファイルを開くことなくそれを行うことができるなら、私はまだD1/2ファイルを持っています。2つのExcel文書の一致する行

私はあなたが始めるだろう、見ていると私はあなたのデータマージのロジックについて教えてくださいここで何かを持っている、これは混乱疑問だった場合

+0

[質問する](http://stackoverflow.com/help/how-to-ask)をご覧ください。 – findwindow

+0

私はあなたが何を意味するかわからない、私はルールに従って、そのセクトインを読んで、私は自分の質問がかなり簡単だと信じています。混乱している部分はありますか? – Luke

+0

あなたはそれを読んだけど、それを理解しましたか?もう一度お試しください。 – findwindow

答えて

0

を必要に応じて、私は明確化の質問に答えることができます申し訳ありません.. ...

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 

End Subの

私だけ起動する2つのファイルをしたように、まったく同じコードは、第二のファイルのために使用されます。

抽出するデータと、マスターファイルなどの内容を置き換える場合は、さらに詳しく入力する必要があります。

関連する問題