Copt pasting data from one workbook to another

Shree1

New Member
Joined
Sep 8, 2014
Messages
29
Hi,

I'm new to VBA so apologies for asking simple questions!

I have a workbook called "ME". I want to write a macro that will import data from columns A1 till J5000 in worksheet"temp" in another workbook called "XY", and put them in a worksheet called "IM" in the original workbook. Can someone please help me with the code. I also want to put in a code that will opne up workbook "XY" in case it is not open.
Thanks!
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

zb134

New Member
Joined
Jun 23, 2014
Messages
38
Hi,

I'm new to VBA so apologies for asking simple questions!

I have a workbook called "ME". I want to write a macro that will import data from columns A1 till J5000 in worksheet"temp" in another workbook called "XY", and put them in a worksheet called "IM" in the original workbook. Can someone please help me with the code. I also want to put in a code that will opne up workbook "XY" in case it is not open.
Thanks!
You will find all the info you need here
 

zb134

New Member
Joined
Jun 23, 2014
Messages
38
Thanks. How do I specify the location path of the source file?

Code:
Sub Copycat()'    Dim vFile As Variant
'    Dim wbCopyTo As Workbook
'    Dim wsCopyTo As Worksheet
'    Dim wbCopyFrom As Workbook
'    Dim wsCopyFrom As Worksheet
'
'
'    Set wbCopyTo = ActiveWorkbook
'    Set wsCopyTo = ActiveSheet
'
'        '-------------------------------------------------------------
'        'Open file with data to be copied
'
'        vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
'        "*.xl*", 1, "Select Excel File", "Open", False)
'
'        'If Cancel then Exit
'        If TypeName(vFile) = "Boolean" Then
'            Exit Sub
'        Else
'        Set wbCopyFrom = Workbooks.Open(vFile)
'        Set wsCopyFrom = wbCopyFrom.Worksheets(1)
'        End If
'
'        '--------------------------------------------------------------
'        'Copy Range 3000 soft limit
'        wsCopyFrom.Range("a1:af3000").Copy
'
'        wsCopyTo.Range("a1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats, _
'                Operation:=xlNone, SkipBlanks:=False, Transpose:=False
'
'
'
'
'
'        wbCopyFrom.Save
'
'
'
'        'Close file that was opened
'        wbCopyFrom.Close SaveChanges:=False
'


'
'End Sub
 

Shree1

New Member
Joined
Sep 8, 2014
Messages
29

ADVERTISEMENT

Oooo, let me try that. Thanks!
 

Shree1

New Member
Joined
Sep 8, 2014
Messages
29
vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _ "*.xl*", 1, "Select Excel File", "Open", False)

did not work.

So, my workbook name is "XY" an dthe filepath is c:...\xy.xls
 

Shree1

New Member
Joined
Sep 8, 2014
Messages
29
The workbook I am opening is "XY" in location c:\mamama\XY.xls. The worksheet that has the data to be copied is called "temp" and the range is A1 to J5000. I want to copy it to a worksheet called "IM" in my active workbook. Can you please tell me how to do that with the above code
 

Watch MrExcel Video

Forum statistics

Threads
1,122,182
Messages
5,594,727
Members
413,927
Latest member
PolAmer

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
Top