How Can I Combine/Merge Multiple Excel Files Into a Single File Horizontally?

njpamdnc

New Member
Joined
Feb 16, 2019
Messages
42
Office Version
  1. 2007
Platform
  1. Windows
Hello...My name is Robert, and I am already familiar with using the Windows command prompt to execute "copy *.xls combine.xls" in order to VERTICALLY join multiple Excel files. However, I am seeking a Windows command prompt function or an Excel macro for HORIZONTALLY merging the workbooks into a single workbook. Furthermore, I am not interested in using Power Query, Linux, Unix, etc. to accomplish this task due to the fact those programs are unfamiliar to me. Any assistance you can provide will be greatly appreciated.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
See if this macro does what you want. Change the code where indicated.
VBA Code:
Public Sub Import_Workbooks_To_Columns()
    
    Dim fileSpec As String, folder As String, fileName As String
    Dim destCell As Range
    Dim wb As Workbook
    
    fileSpec = "C:\folder\path\*.xls"     'CHANGE -location of workbooks and wildcard file spec.
    
    With ActiveSheet
        Set destCell = .Range("A1")
    End With
    
    Application.ScreenUpdating = False
    
    folder = Left(fileSpec, InStrRev(fileSpec, "\"))
    fileName = Dir(fileSpec)
    While fileName <> vbNullString
        Set wb = Workbooks.Open(folder & fileName)
        wb.Worksheets(1).UsedRange.Copy destCell
        wb.Close False
        Set destCell = destCell.Worksheet.Cells(1, destCell.Worksheet.Columns.Count).End(xlToLeft).Offset(, 1)
        fileName = Dir
    Wend

    Application.ScreenUpdating = True
    
    MsgBox "Done"

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,564
Messages
6,125,575
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top