Solved

Tricky copy and paste macro from multiple workbooks

Posted on 2013-01-09
7
189 Views
Last Modified: 2013-01-15
Hi Experts

Need a macro that opens all the workbooks in the c: drive file paths c:\documents and setting\test

One by one and copies the data in worksheet "cm" and and pastes the data onto a master workbook same file path called "Master Template" and into worksheet "cm1". So the data is stacked one under Neath the other...

Workbooks in c: drive file paths c:\documents and setting\test are:-

1. Customer.xls
2. Supplier.xls
3. Temporary.xls
4. Resource.xls
0
Comment
Question by:route217
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Norie
ID: 38759982
Try this which assumes the Master Template worksheet needs to be opened.
Sub Conso()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim strFilename As String

    Set wbDst = Workbooks.Open("C:\Documents and Settings\Test\Master Template.xls")
    
    strFilename = Dir("C:\Documents and Settings\Test\*.xls")
    
    While strFilename <> ""
    
        If strFilename <> "Master Template.xls" Then
        
            Set wbSrc = Workbooks.Open("C:\Documents and Settings\Test\" & strFilename)
            
                 wbSrc.Worksheets("cm").UsedRange.Copy wbDst.Worksheets("cm1").Range("A" & Rows.Count).End(xlUp).Offset(1)

            
            wbSrc.Close
        End If
        
        strFilename = Dir()
        
    Wend
                 
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 38760235
Immoire

Thanks for the feedback... Are saying run the macro from the master file?
0
 

Author Comment

by:route217
ID: 38760252
Ps last question

Immoire this macro will open up all the workbook in the specified c: drive one by one and paste the data into the master file one after the other...
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 33

Expert Comment

by:Norie
ID: 38760289
It will open the master workbook, then one by one open the rest of the xls files in the folder, copy the data from sheet 'cm' to sheet 'cm1' in the master workbook.

If you want to run it from the master workbook it can easily be changed.
0
 

Author Comment

by:route217
ID: 38760403
That would be great if it could be changed to run from master file ... And is the data pasted into master file one after another I.e each file in turn??
0
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 38760637
That's how the data is pasted.

Here's the code so it will run from the master file.
Sub Conso()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim strFilename As String

    Set wbDst = ThisWorkbook  ' Workbooks.Open("C:\Documents and Settings\Test\Master Template.xls")
    
    strFilename = Dir("C:\Documents and Settings\Test\*.xls")
    
    While strFilename <> ""
    
        If strFilename <> wbDst.Name Then
        
            Set wbSrc = Workbooks.Open("C:\Documents and Settings\Test\" & strFilename)
            
                 wbSrc.Worksheets("cm").UsedRange.Copy wbDst.Worksheets("cm1").Range("A" & Rows.Count).End(xlUp).Offset(1)

            
            wbSrc.Close
        End If
        
        strFilename = Dir()
        
    Wend
                 
End Sub

Open in new window

0
 

Author Comment

by:route217
ID: 38779858
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now