Copying multiple cells between workbooks

shakeregg

New Member
Joined
Sep 2, 2018
Messages
39
Hey, I'm new to VBA and I'm wanting to transfer data from a number of workbooks (Sub Workbook 1, Sub Workbook 2, Sub Workbook 3 etc) to a main workbook (Database).

The location of the data contained within all the Sub Workbooks is the same (Sheet1 & A4:A52).

I'm wanting to paste this data into the main workbook which worksheet is called "Raw Data". Hopefully Sub Workbook 1 data will go in Column B4:52, Sub Workbook 2 data in column C4:52 etc etc.

Any help will be mostly appreciated!

Cheers all
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
What is the full path to the folder containing the source files? Are the source files the only files in that folder? What is the extension of the source files ("xlsx,xlsm,xls)?
 
Upvote 0
Thank you for replying!

The full path to the folder containing the source files is: C:\Users\Laura\OneDrive\Documents\Database. This contains both the source files and the main workbook as well but that can be easily changed if needed. Also the file source is xlsm.

Thanks again!
 
Upvote 0
Try:
Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim wkbSource As Workbook, wsDest As Worksheet
    Set wsDest = ThisWorkbook.Sheets("Raw Data")
    Dim lColumn As Long
    lColumn = 2
    Const strPath As String = "C:\Users\Laura\OneDrive\Documents\Database\"
    ChDir strPath
    strextension = Dir(strPath & "*.xlsm")
    Do While strextension <> ""
        If strextension <> ThisWorkbook.Name Then
            Set wkbSource = Workbooks.Open(strPath & strextension)
            With wkbSource
                .Sheets("Sheet1").Range("A4:A52").Copy wsDest.Cells(4, lColumn)
                lColumn = lColumn + 1
                .Close savechanges:=False
            End With
        End If
        strextension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Replace
Code:
lColumn = lColumn + 1
with
Code:
 lColumn = lColumn + 2
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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