'How do i copy columns from one file into another?

i need your help. I have two excel files and i want to do a few things with it. At first i want to copy specific columns from sheet1 in the original file to sheet2 within the orginal file. I accomplished that. But now i also want to copy three specific columns from another workbook(excel file) to sheet2 within the original file. Below you can see my code. The second part of the code (begins with set OpenWb..) doesnt work. Any idea why it doesnt work or any idea for a different approach is much appreciated.

Sub Makro2()
    Range("E2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
    Range("B1").Select
    ActiveSheet.Paste
    Sheets("Tabelle1").Select
    ActiveWindow.SmallScroll Down:=-183
    Range("H2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Tabelle2").Select
    Range("A1").Select
    ActiveSheet.Paste
 
    Set OpenWb = Workbooks.Open("......xlsx")
    LastRowCW = OpenWb.Sheets(1).Range("CW99999").End(xlUp).Row
    OpenWb.Sheets(1).Range("CW2: CW" & LastRowCW).Copy Destination:=ThisWorkbook.Sheets(2).Range("F1")
    LastRowCT = OpenWb.Sheets(1).Range("CT99999").End(xlUp).Row
    OpenWb.Sheets(1).Range("CT2: CT" & LastRowCT).Copy Destination:=ThisWorkbook.Sheets(2).Range("G1")
    LastRowCN = OpenWb.Sheets(1).Range("CN99999").End(xlUp).Row
    OpenWb.Sheets(1).Range("CN2: CN" & LastRowCN).Copy Destination:=ThisWorkbook.Sheets(2).Range("I1")
 
 
    Worksheets(2).Activate
    Columns("B:B").Select
    Selection.TextToColumns Destination:=Range("G1"), DataType:=xlFixedWidth, _
    FieldInfo:=Array(Array(0, 1), Array(12, 1)), TrailingMinusNumbers:=True
 
End Sub


Solution 1:[1]

If i understood correctly, you're trying to Open another Excel file, selecting and copying columns from that file to your original "Sheet2"

With the code below you can open a file, activate that window, copy data and then paste it in "sheet2"

Workbooks.Open Filename:="D:\Documents\Rest.xlsx"
Windows("Rest.xlsx").Activate
Range("A:C").Select
Selection.Copy
Windows("Schwebe.xlsx").Activate
Range("F1").PasteSpecial

I'd advise to start copying just 1 cell from that new file range before anything!

Hope it helps!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1