Macro copy data from sheet and insert.

daniel.s

New Member
Joined
Jun 9, 2010
Messages
27
Hi All,

I need a macro that will copy an entire sheet's data onto another sheet in another workbook.

Is this possible?

I have already created a macro that brings up a message box...then when I click 'OK' you navigate to the data source...its from here I need the data copied.

Many thanks indeed,

Daniel.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Yes it is possible. What are the names of the source and destination workbook and worksheets? Can you post the code you have so far?
 
Upvote 0
The code would be like this

Code:
ActiveSheet.UsedRange.Copy Destination:=Workbooks("Book2.xls").Worksheets("Sheet1").Range("A1")
 
Upvote 0
Hi Jack,

Unfortunately the source worksheet/book name will change. The destination will remain the same. The Desintation is called DATA (sheet name) Cost Validation (workbook name).

Many thanks.
 
Upvote 0
Code so far...

Sub Button3_Click()
Sheets("DATA").Select
resp = MsgBox(prompt:="Please select the AB invoice backup that you" _
& " would like to add, make sure the file is NOT currently open.", _
Buttons:=vbOKCancel)
If resp = vbCancel Then
Exit Sub
End If
'the data would then be inserted into the Sheet named on the top line.
 
Upvote 0
Try something like this

Code:
Sub Button3_Click()
Dim sFile As Variant, wb As Workbook
sFile = Application.GetOpenFilename("Files (*.xls),*.xls", , "Select A File")
If sFile = "False" Then Exit Sub
Set wb = Workbooks.Open(sFile)
wb.Sheets("Sheet1").UsedRange.Copy Destination:=ThisWorkbook.Worksheets("DATA").Range("A1")
wb.Close savechanges:=False
End If
 
Upvote 0
This does not seem to want to open the sheet - I don't think the source worksheet is always called 'Sheet1'.

Thanks.
 
Upvote 0
This worked for me

Code:
Sub Button3_Click()
Dim sFile As Variant, wb As Workbook
sFile = Application.GetOpenFilename("Files (*.xls),*.xls", , "Select A File")
If sFile = "False" Then Exit Sub
Set wb = Workbooks.Open(sFile)
wb.Sheets(1).UsedRange.Copy Destination:=ThisWorkbook.Worksheets("DATA").Range("A1")
wb.Close savechanges:=False
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,830
Messages
6,132,962
Members
449,772
Latest member
Burkie

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