+ Reply to Thread
Results 1 to 5 of 5

Copying a range of data into another Master workbook below existing data

Hybrid View

Grizz Copying a range of data into... 03-21-2014, 12:27 PM
JamesAtOwl Re: Copying a range of data... 03-21-2014, 01:16 PM
JOHN H. DAVIS Re: Copying a range of data... 03-21-2014, 02:48 PM
Grizz Re: Copying a range of data... 03-22-2014, 06:13 AM
JOHN H. DAVIS Re: Copying a range of data... 03-24-2014, 06:24 AM
  1. #1
    Registered User
    Join Date
    06-18-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2013/2016
    Posts
    40

    Copying a range of data into another Master workbook below existing data

    Hello,

    I have a range of weekly data that I need to copy into another workbook, paste it below the data that already exists there and then delete the data from the original workbook. I would love to do this with vba but after hours of searching on how to do this my brain is frazzled.

    I have 50 workbooks that I need to import weekly into one master sheet (Master.xlsm) but they need to be done individually after the weekly data has been checked. The master sheet will therefore have existing data and the new data needs to be appended at the bottom. Also column A will be blank in both workbooks so to find the last used row it will need to look in column B.

    The number of rows in the weekly sheet will also vary rather than be a fixed range so I guess the last used row will also need to be found there too.

    The attached file is a cut down version of my working file showing where the data starts on Row 14, I won't need to copy the headings.

    Any help to get me started would be much appreciated.

    Thanks
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    02-20-2014
    Location
    Lapeer, MI
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: Copying a range of data into another Master workbook below existing data

    I found this a while ago and have used it. It copies from and selected sheets to the one you set as AWS.

    Sub MergeSheets()
    
    ' Appends data from all the selected worksheets onto the end of the
    ' active worksheet.
    
    Const NHR = 1 'Number of header rows to not copy from each MWS
    
    Dim MWS As Worksheet 'Worksheet to be merged (appended)
    Dim AWS As Worksheet 'Worksheet to which the data are transferred
    Dim FAR As Long 'First available row on AWS
    Dim LR As Long 'Last row on the MWS sheets
    
    Set AWS = Workbooks("Master.xlsm").Worksheets("WorksheetNameHere")
    
    For Each MWS In ActiveWindow.SelectedSheets
    If Not MWS Is AWS Then
    FAR = AWS.UsedRange.Cells(AWS.UsedRange.Cells.Count).Row + 1
    LR = MWS.UsedRange.Cells(MWS.UsedRange.Cells.Count).Row
    MWS.Range(MWS.Rows(NHR + 1), MWS.Rows(LR)).Copy AWS.Rows(FAR)
    End If
    Next MWS
    
    End Sub

  3. #3
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copying a range of data into another Master workbook below existing data

    Maybe:

    Sub Grizz()
    Workbooks("Weekly.xls").Sheets("Sheet1").Range("C13:D" & Range("C" & Rows.count).End(3)(1).Row).Copy Workbooks("Master.xls").Sheets("Sheet1").Range("A" & Range("B" & Rows.count).End(3)(1).Row)
    End Sub

  4. #4
    Registered User
    Join Date
    06-18-2009
    Location
    Northampton, England
    MS-Off Ver
    Excel 2013/2016
    Posts
    40

    Re: Copying a range of data into another Master workbook below existing data

    Thank you both for your replies. I have tried both bits of code...John, yours did what I wanted but it didn't add on a second export below the first. James I have tinkered with your code and got it working in a copy of my real file. Unfortunately that file has a named range which it is also copying across which is fine for the first export but brings up an error on the second export saying the name already exists in the destination worksheet. Is there a way of either not copying the named range or deleting the name in the Master file?

    Thanks again for your help

  5. #5
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Copying a range of data into another Master workbook below existing data

    Do you mean like this?

    Sub Grizz()
    Workbooks("Weekly.xls").Sheets("Sheet1").Range("C13:D" & Range("C" & Rows.count).End(3)(1).Row).Copy Workbooks("Master.xls").Sheets("Sheet1").Range("A" & Range("B" & Rows.count).End(3)(2).Row)
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copying data from multiple workbooks to 1 master workbook
    By chilli76 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2014, 12:50 PM
  2. [SOLVED] Copying data from other workbooks and pasting into master workbook
    By jcook1100 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-15-2013, 08:03 AM
  3. Replies: 1
    Last Post: 11-21-2012, 11:23 AM
  4. Copying cells from existing sheets to new row of master sheet in one workbook
    By volcaremos in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-06-2012, 03:53 PM
  5. Replacing the existing Data of workbooks on splitting Data in a Master workbook
    By anchuri_chaitanya in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-04-2012, 11:59 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1