VBA for copy/paste values of all workbooks in a folder

trentbaby9

New Member
Joined
Feb 25, 2013
Messages
9
I'm trying to find and figure out the vba code needed to copy selected cells from all workbooks in a folder and paste the values only into the new "master summary" workbook, incrementing each pasted value to the next available line. I've tried several different codes but still can't seem to get any of them to work.

Folder = Test Folder
Files in Folder: file1.xlsx, file2.xlsx, file3.xlsx
Each file has multiple worksheets, but I only need to copy five cells (A11, B11, C11, D11, E11) from the worksheet labeled Summary.

I then need to paste values only into the "master summary" workbook on the next available line so that no data is overwritten.

Any help is greatly appreciated!
 
Ok, in that case will A11 on the summary sheets always have a value? Or can it sometimes be blank?
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Any of the cells can sometimes be blank or zero.

Eventually, all of the A11 cells will have a name in them, but for now, only one of them does.
 
Upvote 0
In that case how about
Code:
Sub trentbaby()
   Dim Pth As String, Fname As String
   Dim Wbk As Workbook
   Dim ws As Worksheet
   Dim NxtRw As Long
   
   Application.ScreenUpdating = True
   Pth = "C:\MrExcel\Fluff\"
   Fname = Dir(Pth & "*.xls*")
   Set ws = ThisWorkbook.Sheets("Sheet1")
   NxtRw = ws.Cells.Find("*", , xlValues, , xlByRows, xlPrevious, , , False).Offset(1).Row
   Do While Fname <> ""
      Set Wbk = Workbooks.Open(Pth & Fname)
      ws.Range("A" & NxtRw).Resize(, 5).Value = Wbk.Sheets("Summary").Range("A11:E11")
      NxtRw = NxtRw + 1
      Wbk.Close False
      Fname = Dir()
   Loop
End Sub
 
Upvote 0
I forgot to add the Value part again
Code:
      ws.Range("A" & NxtRw).Resize(, 5).Value = Wbk.Sheets("Summary").Range("A11:E11")[COLOR=#ff0000].Value[/COLOR]
 
Upvote 0
Lol, adding the .Value worked! I am so grateful to you Fluff; it works exactly how I needed it to!

Thanks for taking the time to help me :)
 
Upvote 0
Alright, I think it might be close.
On my 2021 Excel, I'm running into :

Run-time error '91':
Object variable or With block variable not set

VBA Code:
NxtRw = ws.Cells.Find("*", , xlValues, , xlByRows, xlPrevious, , , False).Offset(1).Row

Would you have any recommendations on this one?
 
Upvote 0
This issue will take place if the destination workbook is fully blank
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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