Merging Column from multiple workbooks to a specific range of an existing Workbook

danng

New Member
Joined
Nov 12, 2015
Messages
9
Hello Excel experts,

I have been struggling for two days and I really need help from you. I am fairly new to VBA coding. I hope that I can find help here. I want to be able to gather a column from multiple workbooks in the same folder to a specific range of an existing Master workbook.

A few requirements:
1. It doesn't matter where you save these files, as long as these files are in the same folder of the Master workbook, the Master will be able to capture the data.
2. It doesn't matter what file name of these files are.


What I need to transfer:
1. Range I8:I44 of Sheet1 of each file to the Master in Range I9:I45, starting column I and continue with the column J and so on
2. Range L8:L46 of Sheet2 of each file to the Master Sheet2 in Range L9:L47, starting column L and continue with the column M and so on

I tried to build up codes and I still couldn't get the data transferred to the Master.

Please help !!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You need to change the first line from

Code:
Sub MergeColumns()

to

Code:
Private Sub Workbook_Open()

Cheers,

tonyyy
 
Upvote 0
Suggest you post another request for the protected worksheet. The item wasn't in the original scope, and I don't know when I'd be able to get to it.

tonyyy
 
Upvote 0
I solved the problem to run the macro automatically when open the Master file.

I also added these codes at the opening and the closing, but still the VB get stucked because the Master sheet is protected... What is the error there? Please help!


Sub UnprotectAll()
Dim sh As Worksheet
Dim yourPassword As String
yourPassword = "cheval"

For Each sh In ActiveWorkbook.Worksheets
sh.Unprotect Password:=yourPassword
Next sh

End Sub


Sub MergeColumns()

''''' Place this macro workbook in the same folder as your project files


Dim wb1 As Workbook
Dim wb2 As Workbook
Dim directory As String
Dim fileName As String
Dim i As Long
Dim j As Long


Set wb1 = ThisWorkbook
directory = ThisWorkbook.Path & "\"
fileName = Dir(directory & "*.xls?")
i = 9
j = 12

Do While fileName <> ""
If fileName <> wb1.Name Then
Set wb2 = Workbooks.Open(directory & fileName)
wb2.Sheets(1).Range("i7:i43").Copy Destination:=wb1.Sheets(1).Cells(7, i)

i = i + 1
j = j + 1
wb2.Close savechanges:=False
End If
fileName = Dir
Loop

End Sub

Sub ProtectAll()
Dim sh As Worksheet
Dim yourPassword As String
yourPassword = "cheval"

For Each sh In ActiveWorkbook.Worksheets
sh.Protect Password:=yourPassword
Next sh

End Sub
 
Upvote 0
Thank you Tonyyy for your help!!
I figured out how to run the VB in the protected sheet. Thank you so much again for your great help!! Cheers!
 
Upvote 0

Forum statistics

Threads
1,217,310
Messages
6,135,775
Members
449,963
Latest member
ethanong89

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