Copy data from multiple workbooks to a master workbook using VBA

Priyanka298

New Member
Joined
May 1, 2022
Messages
21
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi there,
I have tried the following code to copy and paste the data from source file to destination file, where the code works perfectly if the source file's record are just as value. But in my data, I have multiple files and that files contain records as formatted cells(have attached the image). I am not sure what's wrong in my code. Any help appreciated.
VBA Code:
[
Sub COPYPASTEQLD()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Set wkbDest = Workbooks.Open("C:\Users\Priyanka.Patel\Desktop\VBA\Portfolio\Portfolio Dashboard Week Ending 2022 04 08 - All.xlsx")
    Dim LastRow As Long
    Const strPath As String = "C:\Users\Priyanka.Patel\Desktop\VBA\Week 5\QLD\- DONE\"
    ChDir strPath
    strExtension = Dir("C:\Users\Priyanka.Patel\Desktop\VBA\Week 5\QLD\- DONE\")
    Do While strExtension <> ""
        Set wkbSource = Workbooks.Open(strPath & strExtension)
        With wkbSource
            LastRow = .Sheets("PDR Summary").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Sheets(1).Range("A3:BD" & LastRow).Copy
            wkbDest.Sheets("Active Proj - Detailed Report").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            .Close savechanges:=False
        End With
        strExtension = Dir
    Loop
    
    Application.ScreenUpdating = True
End Sub

]
Also whenever I tried to open my Source file one message window pop-up. First image shows the error window, second and third is the image of my source file, if you check the cells contains some formulas for values. 

Many Thanks
Priyanka
 

Attachments

  • Screenshot (38).png
    Screenshot (38).png
    131.3 KB · Views: 33
  • Screenshot (39).png
    Screenshot (39).png
    150.2 KB · Views: 32
  • Screenshot (40).png
    Screenshot (40).png
    150.3 KB · Views: 33

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Let me explain you, I have shared the copy of my source file and destination file, now in my original source file, the value in cell A3:G3 has some type of formula which is "=Start!B4", after that H3 has "=IF(Start!B11="Capped","T&M",Start!B11)", I3 has "=IF(G3="Very Small","Small Project","PSR")", and each cell containg some kind of formula.

I think this cause the problem in original file, I found that the files I have shared with you works perfectly but my original file wouldn't.

Many thanks,
Priyanka
 
Last edited by a moderator:
Upvote 0
The formulas should not be a problem. Unfortunately, I can't suggest a solution without seeing your original files. Perhaps you could de-sensitize the data in your original files leaving all the formulas and formatting exactly as they are and upload them. I wouldn't need all the data, just 10 or 12 rows would be enough to test the macro.
 
Upvote 0
Replace the current part of the macro with this:
VBA Code:
With wkbSource.Sheets("PDR Summary")
            LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Range("A3:BD" & LastRow).Copy
            wkbDest.Sheets("Active Proj - Detailed Report").Cells(wkbDest.Sheets("Active Proj - Detailed Report").Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            .Close savechanges:=False
        End With
 
Upvote 0
VBA Code:
[/.Close savechanges:=False]
[/QUOTE]
this line shows an error: Run time error 438, Object doesn't support this property or method. 

However, it copies the data correctly, but opened the source file and with the dotted line around A3:BD row (the one we get when we copy something from cell)
 
Upvote 0
Hi mumps,

I tried this code on the same source file but this time I have added more .xslb files in my "C:\Users\Priyanka.Patel\Desktop\VBA\Week 5\QLD\- DONE\" folder, so it runs for the first file and give the error I have mentioned above and sand not running for the rest of the workbooks.
 
Upvote 0
I have removed that line, it works. But it keep all the source files open. I only want the destination file open at the end. Is it possible?
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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