メインコンテンツへスキップ

Excelで複数のブックをXNUMXつのマスターブックに結合するにはどうすればよいですか?

複数のブックをExcelでマスターブックに結合する必要があるときに行き詰まったことがありますか? 最もひどいことは、組み合わせる必要のあるワークブックに複数のワークシートが含まれていることです。 そして、複数のワークブックの指定されたワークシートのみをXNUMXつのワークブックに結合する方法は? このチュートリアルでは、問題を段階的に解決するのに役立ついくつかの便利な方法を示します。


移動またはコピー機能を使用して、複数のワークブックをXNUMXつのワークブックに結合します

結合する必要のあるブックがXNUMXつしかない場合は、[移動]または[コピー]コマンドを使用して、ワークシートを元のブックからマスターブックに手動で移動またはコピーできます。

1.マスターワークブックにマージするワークブックを開きます。

2.マスターワークブックに移動またはコピーする元のワークブックのワークシートを選択します。

注意:

1)。 を押したまま、隣接していない複数のワークシートを選択できます。 Ctrlキー キーを押して、シートタブをXNUMXつずつクリックします。

2)。 複数の隣接するワークシートを選択するには、最初のシートタブをクリックして、 シフト キーを押し、最後のシートタブをクリックしてすべてを選択します。

3)。 任意のシートタブを右クリックして、をクリックすることができます すべてのシートを選択 コンテキストメニューから、ワークブック内のすべてのワークシートを同時に選択します。

3.必要なワークシートを選択したら、[シート]タブを右クリックし、[ 移動またはコピー コンテキストメニューから。 スクリーンショットを参照してください:

4.次に、 移動またはコピー ダイアログがポップアップします。 予約する ドロップダウンで、ワークシートを移動またはコピーするマスターワークブックを選択します。 で終了する移動を選択します シート前 ボックス、チェックボックス コピーを作成する ボックスをクリックし、最後に OK

次に、XNUMXつのワークブックのワークシートをXNUMXつにまとめて表示できます。 上記の手順を繰り返して、ワークシートを他のワークブックからマスターワークブックに移動してください。


複数のワークブックまたは指定したシートのワークブックをVBAを使用してマスターワークブックに結合します

複数のワークブックをXNUMXつにマージする必要がある場合は、次のVBAコードを適用してすばやく実現できます。 次のようにしてください。

1.結合するすべてのワークブックを同じディレクトリの下にXNUMXつにまとめます。

2. Excelファイルを起動します(このワークブックがマスターワークブックになります)。

3。 プレス 他の + F11 キーを押して アプリケーション用のMicrosoftVisual Basic 窓。 の中に アプリケーション用のMicrosoftVisual Basic ウィンドウ、クリック インセット > モジュール、次に以下のVBAコードをモジュールウィンドウにコピーします。

VBAコード1:複数のExcelブックをXNUMXつにマージする

Sub GetSheets()
'Updated by Extendoffice 2019/2/20
Path = "C:\Users\dt\Desktop\dt kte\"
Filename = Dir(Path & "*.xlsx")
  Do While Filename <> ""
  Workbooks.Open Filename:=Path & Filename, ReadOnly:=True
     For Each Sheet In ActiveWorkbook.Sheets
     Sheet.Copy After:=ThisWorkbook.Sheets(1)
  Next Sheet
     Workbooks(Filename).Close
     Filename = Dir()
  Loop
End Sub
	

注意:

1.上記のVBAコードは、マージ後も元のワークブックのシート名を保持します。

2.マスターワークブックのどのワークシートがマージ後にどこから来たのかを区別したい場合は、以下のVBAコード2を適用してください。

3.ワークブックの指定されたワークシートをマスターワークブックに結合するだけの場合は、以下のVBAコード3が役立ちます。

VBAコードでは、「C:\ Users \ DT168 \ Desktop \ KTE \」はフォルダパスです。 VBAコード3では、 "Sheet1、Sheet3"は、マスターワークブックに結合するワークブックの指定されたワークシートです。必要に応じて変更できます。

VBAコード2:ワークブックをXNUMXつにマージします(各ワークシートには、元のファイル名のプレフィックスが付いた名前が付けられます):

Sub MergeWorkbooks()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
On Error Resume Next
xStrPath = "C:\Users\DT168\Desktop\KTE\"
xStrFName = Dir(xStrPath & "*.xlsx")
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
Do While Len(xStrFName) > 0
    Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
    xStrAWBName = ActiveWorkbook.Name
    For Each xWS In ActiveWorkbook.Sheets
    xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.Count)
    Set xMWS = xTWB.Sheets(xTWB.Sheets.Count)
    xMWS.Name = xStrAWBName & "(" & xMWS.Name & ")"
    Next xWS
    Workbooks(xStrAWBName).Close
    xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

VBAコード3:指定したワークブックのワークシートをマスターワークブックにマージします。

Sub MergeSheets2()
'Updated by Extendoffice 2019/2/20
Dim xStrPath As String
Dim xStrFName As String
Dim xWS As Worksheet
Dim xMWS As Worksheet
Dim xTWB As Workbook
Dim xStrAWBName As String
Dim xI As Integer
On Error Resume Next

xStrPath = " C:\Users\DT168\Desktop\KTE\"
xStrName = "Sheet1,Sheet3"

xArr = Split(xStrName, ",")

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set xTWB = ThisWorkbook
xStrFName = Dir(xStrPath & "*.xlsx")
Do While Len(xStrFName) > 0
Workbooks.Open Filename:=xStrPath & xStrFName, ReadOnly:=True
xStrAWBName = ActiveWorkbook.Name
For Each xWS In ActiveWorkbook.Sheets
For xI = 0 To UBound(xArr)
If xWS.Name = xArr(xI) Then
xWS.Copy After:=xTWB.Sheets(xTWB.Sheets.count)
Set xMWS = xTWB.Sheets(xTWB.Sheets.count)
xMWS.Name = xStrAWBName & "(" & xArr(xI) & ")"
Exit For
End If
Next xI
Next xWS
Workbooks(xStrAWBName).Close
xStrFName = Dir()
Loop
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

4。 プレス F5 コードを実行するためのキー。 次に、特定のフォルダー内のワークブックのすべてのワークシートまたは指定されたワークシートが、マスターワークブックに一度に結合されます。


複数のワークブックまたは指定したシートのワークブックをXNUMXつのワークブックに簡単に組み合わせる

幸いにも、 組み合わせる のワークブックユーティリティ Kutools for Excel 複数のワークブックをXNUMXつにマージするのがはるかに簡単になります。 複数のブックを組み合わせてこの関数を機能させる方法を見てみましょう。

申請する前に Kutools for Excelについては 最初にダウンロードしてインストールします.

1.新しいワークブックを作成し、をクリックします クツールズプラス > 組み合わせる。 次に、結合されたすべてのブックを保存する必要があり、保護されたブックに機能を適用できないことを通知するダイアログが表示されます。をクリックしてください。 OK

2。 の中に ワークシートを組み合わせる ウィザード、選択 ワークブックの複数のワークシートをXNUMXつのワークブックに結合します オプションをクリックしてから、 Next ボタン。 スクリーンショットを参照してください:

3。 の中に ワークシートを組み合わせる-ステップ2/3 ダイアログボックスで Add > File or フォルダ Excelファイルを追加するには、XNUMXつにマージします。 Excelファイルを追加したら、をクリックします。 終了 ボタンをクリックし、マスターワークブックを保存するフォルダーを選択します。 スクリーンショットを参照してください:

これで、すべてのワークブックがXNUMXつにマージされました。

上記のXNUMXつの方法と比較すると、 Kutools for Excel 次の利点があります。

  • 1)すべてのワークブックとワークシートがダイアログボックスに一覧表示されます。
  • 2)マージから除外するワークシートについては、チェックを外してください。
  • 3)空白のワークシートは自動的に除外されます。
  • 4)マージ後、元のファイル名がシート名のプレフィックスとして追加されます。
  • この機能のその他の機能については、 こちらをご覧ください.

  このユーティリティの無料トライアル(30日)が必要な場合は、 クリックしてダウンロードしてください、次に、上記の手順に従って操作を適用します。


Excel用Kutools- あなたが常に前もって仕事を終えて、人生を楽しむためにより多くの時間を持っているのを助けます
仕事に追いついたり、自分や家族のために過ごす時間がないことはよくありますか?  Kutools for Excel あなたが対処するのを助けることができます 80% Excel パズルで作業効率が 80% 向上し、家族の世話をして人生を楽しむ時間が増えます。
300 の作業シナリオに対応する 1500 の高度なツールにより、作業がこれまでになく簡単になります。
数式やVBAコードを覚える必要がなくなったので、これからは脳を休ませてください。
複雑で繰り返される操作は、数秒でXNUMX回の処理で実行できます。
毎日何千ものキーボードとマウスの操作を減らし、今は職業病に別れを告げましょう。
3分でExcelのエキスパートになり、すぐに認知され、昇給のプロモーションを手伝ってください。
110,000万人の非常に効果的な人々と300以上の世界的に有名な企業の選択。
あなたの$ 39.0を他の人の$ 4000.0以上のトレーニングに値するようにしてください。
全機能を 30 日間無料でお試しいただけます。 理由のない60日間の返金保証。

Comments (146)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
I have one workbook with 100+ sheets, I want to move all 100+ sheets into another workbook in a single sheet.
This comment was minimized by the moderator on the site
I had to read throught the comments to find suggestions that worked for my application of the VBA CODE 2, but I managed to get it to work doing the following things:
1. make sure to change "C:\Users\DT168\Desktop\KTE\" to your own directory to wherever you have your files are located. don't forget the extra "\" at the end!2. my spreadsheets were extension ".xls", so I deleted the extra "x" in this line, like so: xStrFName = Dir(xStrPath & "*.xlsx")3. I placed all my spreadsheets in a single folder, and only those files were the contents of that folder, the target macro enabled spreadsheet where this vba was running from was saved outside of this folder (hopefully this makes sense).
one thing that I didn't want to mess with though is I only needed to merge the 1st tab of each spreadsheet, but I didn't want to mess with the code so if each workbook you want to merge into one has multiple tabs, this code will grab all of the tabs on each workbook and place them in your target spreadsheet, I had to manually delete all the tabs I didn't want.
if the author of this vba could reply to me, how do you change the code to just copy the 1st tab as opposed to all the tabs?
thank you!
This comment was minimized by the moderator on the site
hi I want a change. If the the sheet name is same then the data should be appended in the same name sheet rather than adding a sheet. for example if i have 10 files with jan, feb, mar same sheetnames. then result should be 1 file having jan, feb, mar only 3 sheets with the data of all 10 files. thanks
This comment was minimized by the moderator on the site
Good morning,

Basically I have to copy the values of another file example c: \ test.xlsx (sheet name "date"):

I have to copy the values from A2: T20


And I have to paste in another Extract.xlsx file on the “Extracts” folder on A2.


PLEASE NOTE: You must run vba when opening the file.
This comment was minimized by the moderator on the site
Hello! I need to merge multiple files into one, that are password protected. All source files use the same password. What changes are needed to the first VBA script to merge the files without having to enter the password each time?
This comment was minimized by the moderator on the site
Hello any one can help me, I want to combine sheet 2 only from 5 different sheet, can you script for me.
This comment was minimized by the moderator on the site
you can use Array function to copy the multiple sheets to combine in one file
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
Sheets(Array("Sheet1","Sheet2")).copy
This comment was minimized by the moderator on the site
hai sir i want know code for copying multiple sheets in one excel to multiple excels
This comment was minimized by the moderator on the site
how to use VBA code 1 to amend and make it runs to combine all the .xlsx files into one excel file and each excel spreedsheet tab in the combined excel file should be named as original file name.thanks
This comment was minimized by the moderator on the site
What part of VBA code 3 specifies the name of the worksheet to be copied?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations