Merging worksheets into a master sheet (with formulas and formats intact)

Arrow081974

New Member
Joined
Aug 4, 2018
Messages
3
Hi all

I'm really hoping somebody maybe able to advise as I've been racking my brains out on this. I'm working on a project where I need to merge multiple excel worksheets (to be supplied by different owners- but in a consistent format) into a single worksheet. I've made a fair amount of progress but now have the following issues.

1. I need the project to also copy across the formulas and formats present into the source file

I was going to use the following code

ActiveSheet.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False = Worksheets("Plan").Range(Cells(erow, 1), Cells(erow, 15))
ActiveSheet.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False = Worksheets("Plan").Range(Cells(erow, 1), Cells(erow, 15))
in addition/replacing

ActiveSheet.Paste Destination:=Worksheets("Plan").Range(Cells(erow, 1), Cells(erow, 15))

2. I also need the ability to apply the formulas present within the source worksheets to the master sheet if new rows are keyed directly into the master worksheet. As the number of rows may flex between source sheets.

Here's my full code so far.

Sub copydateafrommultipleworkbooksintomaster()


Dim Folderpath As String, filepath As String, filename As String


Folderpath = "C:\Users\Adam\Documents\Test environment\business files"
filepath = Folderpath & "*.xlsx*"
filename = Dir(filepath)
Dim lastrow As Long, lastcolumn As Long


Do While filename <> ""
Workbooks.Open (Folderpath & filename)
lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
lastcolumn = ActiveSheet.Cells(1, Columns.Count).End(xlToLeft).Column
Range(Cells(2, 1), Cells(lastrow, lastcolumn)).Copy
Application.DisplayAlerts = False
ActiveWorkbook.Close


erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Plan").Range(Cells(erow, 1), Cells(erow, 15))


filename = Dir
Loop
Application.DisplayAlerts = True
MsgBox "Congratulations. All rows have now been imported :)"


End Sub

Really appreciate any help anybody can offer.

Adam
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,777
Messages
6,126,832
Members
449,343
Latest member
DEWS2031

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