0

たとえば、3 つの Excel ファイルがあり、それぞれに 1 つのワークシートが含まれており、これらの 3 つのワークシートには同じ列ヘッダー名があります。

ファイル A には、列ヘッダー名が「IC」、「名前」の「AA」という名前のワークシートがあります。ファイル B には、列ヘッダー名が「IC」、「名前」の「BB」という名前のワークシートがあります。ファイル C には、列ヘッダー名が「IC」、「名前」の「CC」という名前のワークシートがあります。. . .

ここで、ファイル A、B、C のワークシート「AA」、「BB」、および「CC」の「IC」、「名前」の下の値を、ファイル内の 1 つのワークシートに結合したいと考えています。

ファイル ZZ には、ファイル A、B、および C のすべての行の値を含む列ヘッダー名「IC」、「名前」を持つ「zz」という名前のワークシートがあります...

誰かがそれを行う方法を共有できますか?

ありがとうございました :)

4

3 に答える 3

0

単純にコピペできないの?ファイル A の内容を空のワークブックであるファイル Z にコピーします。次に、ファイル B のすべてのデータ行 (ヘッダーを除く) をコピーし、ファイル Z の既存のデータの下に貼り付けます。ファイル C についても繰り返します。

于 2013-02-12T15:15:42.553 に答える
0

ワークブック (ファイルと呼びます) がどのような規則を使用しているかを知らずに、私はあなたの要求どおりに動作するが、いくつかの仮定を行うマクロを作成しました。これはあなたが求めるとおりに機能しますが、ファイルに基づいていくつかの変更が必要になる場合があります。

仮定:

  • すべてのワークブック ヘッダー行ICおよびは、それぞれNameセルA1およびにあります。B1
  • このマクロを実行する前に、すべてのブックが開かれます
  • マクロはParent Workbook、最終結果を格納する WorkBook であると想定されるから開始されます。
  • 各ワークブックのすべての値は、そのワークブックの最初のシートにあります

コード

Public Sub CombineAllOpenWorkbooks()
    Dim parentWb As Workbook, childWb As Workbook
    Dim destinationWs As Worksheet, sourceWs As Worksheet

    Dim highestRowCount As Integer
    Dim firstColumnRowCount As Integer
    Dim secondColumnRowCount As Integer

    Application.ScreenUpdating = False

    'this holds reference to the parent workbook, which is where all the values go
    Set parentWb = Application.Workbooks(ThisWorkbook.Name)
    Set destinationWs = parentWb.Sheets(1)

    'for each workbook open that isn't the aprent workbook, find the last cell,
    'select it, copy its values, then paste them at the end of the parent workbooks
    'current values
    For Each childWb In Application.Workbooks
        If childWb.Name <> parentWb.Name Then
            Set sourceWs = childWb.Sheets(1)
            firstColumnRowCount = sourceWs.Cells(Rows.Count, 1).End(xlUp).Row
            secondColumnRowCount = sourceWs.Cells(Rows.Count, 2).End(xlUp).Row

            highestRowCount = firstColumnRowCount
            If firstColumnRowCount < secondColumnRowCount Then
                highestRowCount = secondColumnRowCount
            End If

            'copy from below the 'IC/Name' headers to the last cell that contains values
            sourceWs.Range(sourceWs.Cells(2, 1), sourceWs.Cells(highestRowCount, 2)).Copy

            firstColumnRowCount = destinationWs.Cells(Rows.Count, 1).End(xlUp).Row
            secondColumnRowCount = destinationWs.Cells(Rows.Count, 2).End(xlUp).Row

            highestRowCount = firstColumnRowCount
            If firstColumnRowCount < secondColumnRowCount Then
                highestRowCount = secondColumnRowCount
            End If

            'paste the previously copied values to the end of the parent workbokos values
            destinationWs.Range("A" & highestRowCount + 1).PasteSpecial Paste:=xlPasteValues
        End If
    Next childWb
    Application.ScreenUpdating = True
End Sub

この VBA をワークブックに追加するDeveloper Tabは、PARENT ワークブックの を開き、メニューから選択Visual Basicし、左側のメニューから開きSheet 1、そこにコードを貼り付ける必要があります。

テスト中に使用したワークブックの画像を次に示します (ParentWorkbook、FileA、FileB)。

マクロを実行する前の 3 つのワークブックすべて: ここに画像の説明を入力

マクロ実行後の親ワークブック: ここに画像の説明を入力

このコードは迅速に作成され、限定的なテストが行​​われたことに注意してください。それは確かにクリーンアップでき、コード内の冗長性を取り除くことができます。その目的は、開始することです。どの部分でもご不明な点がございましたら、喜んでご説明いたします。

于 2013-02-12T17:34:09.467 に答える
0

私はこのソフトウェアを試してみましたが、うまくいきました: http://bulkfilemerger.com/index1

于 2013-02-13T15:47:27.503 に答える