Excel 2016 VBA to consolidate data from several workbooks into one book

Kthom019

New Member
Joined
May 16, 2017
Messages
46
Can someone help with a macro to consolidate data from several workbooks into one workbook. I recorded a macro by copying and pasting the data from their workbooks into the required worksheet in the new workbook. But my mind is saying that there is another way to do this; is there?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Did you see my modified code in post#19?
 
Upvote 0
Yes thanks, I am trying to understand it to modify it. I did the below but I am still getting the message. I do not understand the second script.

Sub Consolidate_Actual_Files()


Dim Ary As Variant
Dim i As Long
Dim wbk As Workbook

Set wbk = Workbooks("Forecast test1.xlsm")
Ary = Array("JAS-1", "BAS-1", "TRAS-1", "BAR-1")

For i = 0 To UBound(Ary)
Workbooks(Ary(i) & ".xlsm").Sheets("FCAST").Range("D3:O369").Copy wbk.Sheets(Ary(i) & "-1").Range("D3")
Next i
End Sub


Did you see my modified code in post#19?
 
Upvote 0
It seems as if your having problems with my code and Fluff code.

One thing that is important to remember is that all sheet names and Workbook names must be exact with extensions.

And I just wrote a sample to show you how to copy One Workbooks range to another Workbooks range.

You must have the workbook name the sheet name and then the range just like in my example.

And all Workbooks must be open.
 
Upvote 0
I understand this script, thank you very much:)
Well I'm not sure what your saying.

Do you really have a Workbook named:
Userform 25.xlsm

I think not.

You need to change this to what your workbook is named.

If your workbook is named "Jas" then change my script.
 
Upvote 0
Yes I did.
Yes thanks, I am trying to understand it to modify it. I did the below but I am still getting the message. I do not understand the second script.

Sub Consolidate_Actual_Files()


Dim Ary As Variant
Dim i As Long
Dim wbk As Workbook

Set wbk = Workbooks("Forecast test1.xlsm")
Ary = Array("JAS-1", "BAS-1", "TRAS-1", "BAR-1")

For i = 0 To UBound(Ary)
Workbooks(Ary(i) & ".xlsm").Sheets("FCAST").Range("D3:O369").Copy wbk.Sheets(Ary(i) & "-1").Range("D3")
Next i
End Sub
 
Upvote 0
Try changing this
Code:
Ary = Array("JAS-1", "BAS-1", "TRAS-1", "BAR-1")
to
Code:
   Ary = Array("JAS", "BAS", "TAS", "BAR")
 
Upvote 0
Thank you both for assisting me. I gained understanding which was necessary. I then learnt that if the sheet I am copying from has linked formulas to another sheet or workbook, I can write the VBA to include copy paste special values. I also learnt how to add to the code to protect the sheet after updating. Your help was greatly appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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