Sub JoinExcelFiles()
Dim folderPath As String ' Variable to hold the path of the folder
Dim fileName As String ' Variable to hold each file name
Dim wsMain As Worksheet ' Variable for the main worksheet in the current workbook
Dim wbSource As Workbook ' Variable for the source workbook (files to be joined)
Dim wsSource As Worksheet ' Variable for the source worksheet (in each file)
Dim lastRowMain As Long ' Variable to hold the last row in the main worksheet
Dim lastRowSource As Long ' Variable to hold the last row in the source worksheet
' Set the folder path where your Excel files are located
folderPath = "C:\Path\To\Your\Folder\" ' Change this to your folder path
' Set the worksheet where you want to combine the data (the active worksheet in this case)
Set wsMain = ThisWorkbook.Sheets(1) ' Change the index or name if needed
' Get the first file in the specified folder
fileName = Dir(folderPath & "*.xlsx") ' Change "*.xlsx" if you're using a different file type
' Loop through all files in the folder
Do While fileName <> ""
' Open the source workbook
Set wbSource = Workbooks.Open(folderPath & fileName)
' Assuming we want the first sheet in the source workbook
Set wsSource = wbSource.Sheets(1)
' Find the last row in the main worksheet
lastRowMain = wsMain.Cells(wsMain.Rows.Count, "A").End(xlUp).Row + 1
' Find the last row in the source worksheet
lastRowSource = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row
' Copy the data from the source worksheet to the main worksheet
' This copies all data from the first row to the last row of the source sheet
wsSource.Range("A1:A" & lastRowSource).EntireRow.Copy wsMain.Cells(lastRowMain, 1)