Help requested - Copy Paste, from one workbook to another workbook.

Dingoz2012

Board Regular
Joined
Jan 29, 2012
Messages
163
Mind blank.

I have two workbooks. Workbook 1 is the reporting workbook, has 2 sheets in it. Sheet1 is called Data, sheet2 is Count by Member (where I have all the graphs and results set out. Workbook 2 gets labelled with the date that it was created on. This workbook is where multiple workbooks data is consolidated.

I'm drawing a mind blank on how to proceed to open workbook2 , and then copy all the cells from sheet1 into Workbook 1 on the sheet named Data, when the user clicks on a shape which is assigned a macro in workbook 1

* So the managers don't have to open up the results workbook, select all, ctrl c, and then click in the main workbook and click ctrl v.


Any help greatly appreciated as always.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
in workbook1 record a macro where you open the second workbook then select the first workbook - this will give you the code..........
 
Upvote 0
What is the actual full name of Workbook2 including the extension (xlsx, xlsm)? What is the name of Sheet1 in Workbook2? Where on the Data sheet in Workbook1 do you want to paste the copied data? What is the full path to the folder containing Workbook2?
 
Upvote 0
Code:
Workbook 2 gets labelled with the date that it was created on
Is the date plus file extension the full name, or does it have a constant such as "Main" & Format(Date, "mm-dd-yyyy")?
 
Upvote 0
How about
Code:
Sub Dingoz2012()
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Ws1 As Worksheet
   
   Set Ws1 = ThisWorkbook.Sheets("Data")
   Fname = Application.GetOpenFilename
   Set Wbk = Workbooks.Open(Fname)
   Wbk.Sheets("Sheet1").UsedRange.Copy Ws1.Range("A" & Rows.Count).End(xlUp).Offset(1)
   Wbk.Close False
End Sub
 
Upvote 0
How about
Code:
Sub Dingoz2012()
   Dim Fname As String
   Dim Wbk As Workbook
   Dim Ws1 As Worksheet
   
   Set Ws1 = ThisWorkbook.Sheets("Data")
   Fname = Application.GetOpenFilename
   Set Wbk = Workbooks.Open(Fname)
   Wbk.Sheets("Sheet1").UsedRange.Copy Ws1.Range("A" & Rows.Count).End(xlUp).Offset(1)
   Wbk.Close False
End Sub
that's cheating, @Fluff. Now we may never solve the mystery of workbook 2.
 
Upvote 0
Code:
Workbook 2 gets labelled with the date that it was created on
Is the date plus file extension the full name, or does it have a constant such as "Main" & Format(Date, "mm-dd-yyyy")?


Mystery solved. :) Sorry I forgot to mention. Workbook 2 is always saved as "Backup Date" & todays date & .xls, and has only one sheet in it "Sheet1" It opens with the code I have already, just was stuck on the copy and pasting the data from WBK2 "Sheet1" into WBK 1 "Data"

Thankyou Fluff, that helped a lot. Added in a clear sheet command, to wipe all the data. New stuff gets pasted in like a boss. :)


Only the one thing left to figure out....
 
Last edited:
Upvote 0
How about
Code:
   Ws1.UsedRange.Clear
   Wbk.Sheets("Sheet1").UsedRange.Copy Ws1.Range("A1")
 
Upvote 0
How about
Code:
   Ws1.UsedRange.Clear
   Wbk.Sheets("Sheet1").UsedRange.Copy Ws1.Range("A1")

Worked like a charm. Only thing left to figure out is how to not have the folder open, and the user select the file. Would like to have this happen in the background. File will always be labelled "Backup Date" & todays date & .xlsx
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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