Results 1 to 13 of 13

Copy a range of cells from multiple worksheets in multiple workbooks

Threaded View

  1. #1
    Registered User
    Join Date
    11-19-2020
    Location
    Adelaide, South Australia
    MS-Off Ver
    Office 365
    Posts
    12

    Copy a range of cells from multiple worksheets in multiple workbooks

    Hello

    I have a macro that allows me to copy a range of cells from a nominated worksheet that exists in several workbooks from a localised folder into one master sheet, see code below. It works really well I especially like being able to change the worksheet names and range of cells as depending on the project I am working on they may vary.

    However I'd like to expand on this macro and instead of updating the worksheet name each time I want to copy data, I'd like to add all the worksheet names into the macro and have the ranges appear on new worksheets in the master (labelled with the name of the worksheet they have been copied from). See example attached (includes codes as well).

    I'd appreciate any help you can give on how to achieve this.

    Claire


    Sub CopyRange()
     Application.ScreenUpdating = False
     Dim wkbDest As Workbook
     Dim wkbSource As Workbook
     Set wkbDest = ThisWorkbook
     Dim LastRow As Long
     Const strPath As String = "C:\Users\Desktop\StarTrek\"
     ChDir strPath
     strExtension = Dir("*.xls*")
     Do While strExtension <> ""
     Set wkbSource = Workbooks.Open(strPath & strExtension)
     With wkbSource
     LastRow = .Sheets("project_level1A").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
     
     
    Dim rLastCell As Range
    
    Set rLastCell = wkbDest.Sheets("Master").Cells.Find(What:="*", After:=wkbDest.Sheets("Master").Cells(1, 1), LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False)
     
     If rLastCell Is Nothing Then Set rLastCell = wkbDest.Sheets("Master").Cells(1, 1)
     
     wkbDest.Sheets("Master").Cells(2, rLastCell.Column).Offset(-1, 1).Value = wkbSource.Name
     
     wkbDest.Sheets("Master").Cells(2, rLastCell.Column + 1).Resize(LastRow, 4).Value = .Sheets("project_level1A").Range("a1:d" & LastRow).Value
     .Close savechanges:=False
                                                                                                                                            
     End With
     strExtension = Dir
     Loop
     Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files
    Last edited by mclaire; 11-23-2020 at 10:54 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 03-03-2016, 10:18 AM
  2. Trying to finish a VBA code to copy cells from multiple workbooks and worksheets
    By sweetnasty in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-10-2014, 11:56 PM
  3. [SOLVED] VBA code to copy cell range from all worksheets for multiple workbooks
    By Beany213 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-21-2013, 12:34 PM
  4. Replies: 20
    Last Post: 03-13-2013, 04:15 PM
  5. Copy/Paste Range of Data from Multiple Workbooks/Worksheets to Master Workbook/Worksheets
    By NumberCruncher311 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-19-2013, 08:21 PM
  6. [SOLVED] Copy cells from multiple worksheets and workbooks to one master workbook
    By Concept in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-30-2012, 01:42 PM
  7. copy selected range from multiple workbooks into multiple worksheets in one workbook
    By novak100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2012, 05:52 AM

Tags for this Thread

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