Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everybody,
Does any body knows how i can get the WorkSheet in WorkBook1 and put it in Worksheet2 of Workbook2 by clickling a bottom?

I need a macro to do that.
I try to modify some code but it doesn't work. Here is the code:

VB
Sub test()
' Get customer workbook...
Dim customerBook As Workbook
Dim filter As String
Dim caption As String
Dim customerFilename As String
Dim customerWorkbook As Workbook
Dim targetWorkbook As Workbook

' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook

' get the customer workbook
filter = "Text files (*.xlsx),*.xlsx"
caption = "Please Select an input file "
customerFilename = Application.GetOpenFilename(filter, , caption)

Set customerWorkbook = Application.Workbooks.Open(customerFilename)


' copy data from customer to target workbook
Dim targetSheet As Worksheet
Set targetSheet = targetWorkbook.Worksheets(1)
Dim sourceSheet As Worksheet
Set sourceSheet = customerWorkbook.Worksheets(1)

'Workbooks("PGT.xlsx").Worksheets(1).Copy After:=Workbooks("Classeur1.xlsx").ActiveSheet


Close customer workbook
customerWorkbook.Close
End Sub


Thanks
Posted
Comments
Richard MacCutchan 8-Jul-14 8:59am    
I try to modify some code but it doesn't work.
What doesn't work? Please provide proper details of your problem.
alonetmr 8-Jul-14 10:25am    
The problem is here:
Collapse | Copy Code
Workbooks("PGT.xlsx").Worksheets(1).Copy After:=Workbooks("Classeur1.xlsx").ActiveSheet
I get the information in other worksheet. I don't want that. I need my information in the same worksheet where i have the bottom.

By tha way, i get not the same format of the worksheet1. I mean, i want get the values and the same format (colors, size, etc).

Thanks

1 solution

It's simple!
VB
sourceSheet.Copy After:=targetWorksheet


MSDN documentation: Worksheet.Copy Method (Excel)[^]
 
Share this answer
 
v2
Comments
alonetmr 8-Jul-14 15:12pm    
Hi Maciej,
I tried your solution but it did not work.

I get an Compilation Error. argument not found.

The error is here: (Afte:=
Maciej Los 8-Jul-14 16:40pm    
See updated answer ;)
alonetmr 8-Jul-14 17:56pm    
the second solution it doesn't work :(
alonetmr 8-Jul-14 17:56pm    
thanks again Maciej but it doesn't work :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900