Copying Between Workbooks VBA

Gregorys05

Board Regular
Joined
Sep 24, 2008
Messages
217
Hi Guys,
I have the below code that i recorded but is there a better way of copying and pasting data from one workbook to another.
Code:
Windows("India Errors Report.xls").Activate
    Range("D4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("QAChecker.xls").Activate
    Sheets("QAChecker").Select
    Range("C2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("India Errors Report.xls").Activate
    Range("F4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("QAChecker.xls").Activate
    Sheets("Error Type").Select
    Range("C2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Windows("India Errors Report.xls").Activate
    Range("G4").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows("QAChecker.xls").Activate
    Sheets("Processor").Select
    Range("C2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("F20").Select

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
There is a lot that can be cleaned up in that. First thing to clean up is getting rid of all those select/selection statements.

What is the name of the sheet you are pulling data from in the "India Errors Report.xls" file?
 
Upvote 0
Try the following:

Code:
Dim wb1 As Workbook, _
    ws1 As Worksheet, _
    wb2 As Workbook, _
    LR  As Long
    
Set wb1 = Workbooks("India Errors Report.xls")
Set ws1 = wb1.Sheets("Error")

Set wb2 = Workbooks("QAChecker.xls")

LR = ws1.Range("D" & Rows.Count).End(xlUp).Row

ws1.Range("D4:D" & LR).Copy
wb2.Sheets("QAChecker").Range("C2").PasteSpecial Paste:=xlPasteValues
ws1.Range("F4:F" & LR).Copy
wb2.Sheets("Error Type").Range("C2").PasteSpecial Paste:=xlPasteValues
ws1.Range("G4:G" & LR).Copy
wb2.Sheets("Processor").Range("C2").PasteSpecial Paste:=xlPasteValues
 
Upvote 0

Forum statistics

Threads
1,224,514
Messages
6,179,220
Members
452,895
Latest member
BILLING GUY

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