Help! : how can i copy paste to 2 workbooks at the same time?

htoh2

New Member
Joined
Oct 20, 2010
Messages
25
Greetings to all experts,

I'm a novice in VB codings and would like to seek some help from the experts regarding copy pasting to 2 workbooks at the same time.

I had a set of codes which allow me to copy my data from Workbook A to
Workbook B, however, instead of pasting to workbook B only, i wanted to paste to Workbook C as well.

Experts, can you help me on this? How should i code it such that it will execute the code and paste the data to Workbook B and Workbook C at the same time?

Pls feel free to ask me if you have any doubts.
Your help will be greatly appreciated. ;)

Thank you very much :LOL:

Best regards,
htoh2
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Here is some sample Code that opens a second workbook, Copies and Paste Values from a Range of Cells from the Worksheet of the second workbook to a sheet of the first workbook.

Code:
Public Function OpenWorkBook()
Dim wrkbook As Workbook, wrkbook2 As Workbook
Dim mySheet As Worksheet, mySheet2 As Worksheet
Dim MyRange As Range, MyRange2 As Range, Rng As Range

Workbooks.Open Filename:="E:\mdb\hrz1999.xls", UpdateLinks:=False

Set wrkbook = Workbooks("Hrz1999.xls")
Set mySheet = wrkbook.Worksheets("JAN")
Set MyRange = mySheet.Range("A1:B11")
MyRange.Copy

'This is current workbook from where the Code is Run
'You can address the workbooks with its Index number 0, 1 etc.
'depending on the order in which you have opened each one.

Set wrkbook2 = Workbooks("MacroTrials.xls")
Set mySheet2 = wrkbook2.Worksheets("Sheet1")
Set MyRange2 = mySheet2.Range("d1:E11")
MyRange2.PasteSpecial xlPasteValues

'Cell by cell transfer (not advisable)
Set mySheet = wrkbook.Worksheets("FEB")
For Each Rng In mySheet.Range("A1:B11")
    Rng.Copy
    mySheet2.Range(Rng.Address).PasteSpecial xlPasteValues
Next

End Function
You can open any number of workbooks in this way and address their Worksheets, Range of Cells etc. and transfer data between them.

In the above example I have given Range Addresses as constants. Depending on what you are trying to do the Parameters like Worksheet Names, Range addresses etc. can be dynamically defined to give flexibility to the code.
 
Upvote 0

Forum statistics

Threads
1,217,382
Messages
6,136,239
Members
450,000
Latest member
jgp19

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