flowchart TD
Yokohama[横浜店] -->|データ転記| C[売上集計ファイルに統合]
Sapporo[札幌店] -->|データ転記| C
Sendai[仙台店] -->|データ転記| C
Osaka[大阪店] -->|データ転記| C
Tokyo[東京店] -->|データ転記| C
Naha[那覇店] -->|データ転記| C
Fukuoka[福岡店] -->|データ転記| C
Nagoya[名古屋店] -->|データ転記| C
Sub ConsolidateSalesData()
Dim folderPath As String
Dim fileName As String
Dim wsMaster As Worksheet
Dim wsStore As Worksheet
Dim lastRowMaster As Long
Dim lastRowStore As Long
Dim currentRow As Long
' 店舗売上ファイルが格納されているフォルダのパスを設定
folderPath = ThisWorkbook.Path & "\店舗別売上\"
' マスターワークシートを設定
Set wsMaster = ThisWorkbook.Sheets("Sheet1") ' マスターシートの名前を適宜変更
' マスターワークシートの既存データをクリア
wsMaster.Cells.ClearContents
' マスターワークシートにヘッダーを追加
wsMaster.Range("A1:G1").Value =Array("日付","店舗","商品コード","商品名","単価","数量","売上金額")
' データ貼り付けの初期行を設定
lastRowMaster =2
' フォルダ内の各ファイルをループ
fileName =Dir(folderPath &"*.xlsx")
Do While fileName <>""
' 現在の店舗売上ファイルを開く
Workbooks.Open folderPath & fileName
' 現在の店舗売上ファイルのワークシートを設定
Set wsStore =Workbooks(fileName).Sheets(1) ' データが最初のシートにあると仮定
' 店舗ワークシートの最終行を取得
lastRowStore = wsStore.Cells(wsStore.Rows.Count,"A").End(xlUp).Row
' 店舗ワークシートからマスターワークシートにデータをコピー
wsStore.Range("A2:G"& lastRowStore).Copy Destination:=wsMaster.Range("A"& lastRowMaster)
' マスターワークシートの最終行を更新
lastRowMaster = wsMaster.Cells(wsMaster.Rows.Count,"A").End(xlUp).Row +1
' 店舗売上ファイルを閉じる
Workbooks(fileName).Close SaveChanges:=False
' 次のファイル名を取得
fileName = Dir
Loop
MsgBox "売上データの統合が完了しました!", vbInformation
End Sub