I want to take data from another Workbook into the Master File

amo

Board Regular
Joined
Apr 14, 2020
Messages
141
Office Version
  1. 2010
Platform
  1. Windows
I want to take data from another Workbook into the Master File
For the data taken ... the columns are not the same ... and only a few columns are taken
so I have a copy paste idea per column ....

However, if you copy a lot of columns, it is very unlikely if I copy and paste per column
Is there a more practical way?

and when I run it, an error also appears ... but if clicked OK ... it still runs

this my code
VBA Code:
Sub copy()
    Dim FileToOpen As Variant
    Dim OpenBook As Workbook
    Application.ScreenUpdating = False
    FileToOpen = Application.GetOpenFilename()
    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        OpenBook.Sheets(1).Range("A1:A2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("B2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("B1:B2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("C2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("E1:E2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("E2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("C1:C2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("F2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("D1:D2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("G2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("F1:F2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("H2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("H1:H2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("H2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("I1:I2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("I2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("J1:J2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("J2").PasteSpecial xlPasteValues
        OpenBook.Sheets(1).Range("H1:H2000").Copy
        ThisWorkbook.Worksheets("Sheet1").Range("J2").PasteSpecial xlPasteValues
        OpenBook.Close False
        

        
        
    End If
    Application.ScreenUpdating = True
End Sub
 

Attachments

  • EROOR.png
    EROOR.png
    9 KB · Views: 4

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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