Combine files side by side in excel using VBA

preview_player
Показать описание
Sub sidemerge()

Dim filenames() As Variant
Dim file As Workbook
Dim results As Workbook
Dim lastrow As Integer
Dim i As Integer

Application.ScreenUpdating = False

Set results = ActiveWorkbook

filenames() = Application.GetOpenFilename(MultiSelect:=True)

For i = 1 To Application.CountA(filenames)
Set file = Application.Workbooks.Open(filenames(i))
lastrow = file.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
If i = 1 Then
file.Sheets(1).Range("A1:B" & lastrow).Copy results.ActiveSheet.Cells(1, 1)
Else
file.Sheets(1).Range("B1:B" & lastrow).Copy results.ActiveSheet.Cells(1, i + 1)
End If
file.Close
Next i

Application.ScreenUpdating = True

End Sub
Рекомендации по теме
Комментарии
Автор

Hi Karina, I have a question (not related to this video). I have a table (row and column array) of tasks for each month of 2022 and 2023. I need to create a smaller dynamic table that, by choosing a month and year from combo boxes, excel gives me a list of all the tasks for that month and year on a separate tab or the same tab. Could you please let me know if you have any video that could help me? Thanks a lot!

RashidKaveh
Автор

could you please put the workbook so we can practice with this Combine files side by side in excel using VBA

ahmedramadan-xykt