OzGrid

How to copy columns from multiple workbooks and paste into one worksheet

< Back to Search results

 Category: [Excel]  Demo Available 

How to copy columns from multiple workbooks and paste into one worksheet

 

Requirement:

 

The user needs a macro, to copy specific column from multiple workbooks and then paste it in master workbook. All workbooks are in one folder with .xls extension.

Every single file has the same style, with the same number of sheets, names etc.

For example:
Macro is in master woorkbook named "All data". Main worksheet where I need to paste columns is "List". Location of all files is C:\Documents.

The user needs to copy data from every single file chosen:
Worksheet "U_Emiss_t" from range D1:D191.

Then the user wants to paste it in master workbook, in worksheet called "List". The user needs to start from column D, because in columns A, B and C I have some constant data.


Macro should be able to find first empty column and then paste.

It's a problem because I always used a macros with pasting rows, not columns, and my skills are on begginers level.

The user needs more than 200 files to process (every single week).

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/1196089-copy-columns-from-multiple-workbooks-and-paste-into-one-worksheet

 

 

Solution:

 

This should copy all 4th Columns From All Workbooks into Master providing that all, incl Workbook with code ("Master"?) are saved in one and the same Folder.
Change references, like Sheet names, as required.

Code:
Sub Get_Columns()
    Dim sPath As String
    Dim sFil As String
    Dim owb As Workbook
    Dim twb As Workbook

    With Application
        .Calculation = xlCalculationManual
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set twb = ThisWorkbook
    sPath = ThisWorkbook.Path & "\"
    sFil = Dir(sPath & "*.xl*")

    Do While sFil <> "" And sFil <> twb.Name
        Set owb = Workbooks.Open(sPath & sFil)
        owb.Sheets("data").Columns(4).Copy twb.Sheets("report").Cells(1, Columns.Count).End(xlToLeft).Offset(, 1)    '<----- Change sheet names
        owb.Close False 'Close no save
        sFil = Dir
    Loop

        With Application
        .Calculation = xlAutomatic
        .EnableEvents = True
        .ScreenUpdating = True
    End With
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by jolivanes.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to use a Macro to copy rows from multiple worksheets based on a cell value greater than zero
How to read only open an excel workbook (multiple users simultaneously)
How to extract multiple emails separated with semicolon and brackets
How to use IF formula with multiple criteria

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.

klxdate.com kl escorts

Gallery



stars (0 Reviews)