+ Reply to Thread
Results 1 to 1 of 1

Copy data from sheet into master worbook and save as new workbook. Repeat for all sheets

  1. #1
    Registered User
    Join Date
    01-06-2024
    Location
    Frankfurt
    MS-Off Ver
    Office 365
    Posts
    15

    Copy data from sheet into master worbook and save as new workbook. Repeat for all sheets

    SOLVED

    I used the code inserted below with changes to the path names.


    Hello,

    I have 3 workbooks in C:\Folder A

    Data.xlsm (includes 10 worksheets named by year. e.g 2012, 2011, 2012 etc....)
    Master.xlsm (includes 2 worksheets named "Criteria" and "others")
    Summary.xlsm

    I would like a macro placed in the Summary workbook to do the following:

    1. Open the Data and Master workbooks
    2. Copy range ("A2:C400") from Data Sheet("2012")
    3. Paste into same range ("A2:C400") in the Master workbook, Sheet("Criteria")
    4. Save as New Workbook in New Folder C:\Folder "B" with the name of the Data sheet. i.e 2012.xslm
    5. Repeat for the other 9 worksheets in the Data workbook.

    Result: 10 new workbooks in Folder B with the data from the different worksheets in the Data workbook.


    Can you help please?

    Thanks

    Czap




    Sub CopyDataToNewWorkbooks()
    Dim dataWorkbook As Workbook
    Dim masterWorkbook As Workbook
    Dim summaryWorkbook As Workbook
    Dim dataSheet As Worksheet
    Dim masterSheet As Worksheet
    Dim newWorkbook As Workbook
    Dim newFolderPath As String
    Dim yearSheet As Worksheet
    Dim dataRange As Range
    Dim targetRange As Range

    ' Set the paths and filenames
    Dim dataPath As String
    Dim masterPath As String
    Dim summaryPath As String

    dataPath = "C:\Folder A\Data.xlsm"
    masterPath = "C:\Folder A\Master.xlsm"
    summaryPath = "C:\Folder A\Summary.xlsm"

    ' Set the target folder path for new workbooks
    newFolderPath = "C:\Folder B"

    ' Open workbooks
    Set dataWorkbook = Workbooks.Open(dataPath)
    Set masterWorkbook = Workbooks.Open(masterPath)
    Set summaryWorkbook = Workbooks.Open(summaryPath)

    ' Loop through each year sheet in the Data workbook
    For Each yearSheet In dataWorkbook.Sheets
    If yearSheet.Name <> "Criteria" And yearSheet.Name <> "others" Then
    ' Set source and target ranges
    Set dataRange = yearSheet.Range("A2:C400")
    Set masterSheet = masterWorkbook.Sheets("others")
    Set targetRange = masterSheet.Range("A2:C400")

    ' Copy data from Data workbook to Master workbook
    targetRange.Value = dataRange.Value

    ' Create a new workbook and save with the year sheet name
    Set newWorkbook = Workbooks.Add
    newWorkbook.Sheets(1).Range("A1").Value = targetRange.Value
    newWorkbook.SaveAs newFolderPath & yearSheet.Name & ".xlsm", FileFormat:=52 ' xlOpenXMLWorkbookMacroEnabled
    newWorkbook.Close SaveChanges:=False
    End If
    Next yearSheet

    ' Close workbooks
    dataWorkbook.Close SaveChanges:=False
    masterWorkbook.Close SaveChanges:=True ' Save changes made in Master workbook
    summaryWorkbook.Close SaveChanges:=False
    End Sub
    Last edited by czap1; 01-16-2024 at 12:45 PM. Reason: Solved it

+ 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. [SOLVED] Copy data from selected sheet of multiple workbook & copy in master worksheet of workbook
    By sanjuss2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2021, 12:16 PM
  2. [SOLVED] Macro to copy Master sheet to all other sheets in workbook
    By phbryan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-20-2021, 09:26 PM
  3. [SOLVED] Copy data from master sheet in workbook to monthly sheets
    By joserborges in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-27-2014, 09:24 PM
  4. Marcto to copy sheets from one workbook to a master sheet, for all files in folder
    By crombieguy91 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2013, 11:12 AM
  5. Creating a master sheet using data from other sheets in the workbook.
    By Chaos247 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-22-2013, 07:57 AM
  6. Copy data from workbook, create new workbook, paste data to new worbook?
    By mpkavanagh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-16-2011, 06:39 PM
  7. Copy Sheet with Command Button to new Worbook and assign macro in new workbook
    By grey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-07-2010, 05:33 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