Copy column A and column B from another file

thelad

Board Regular
Joined
Jan 28, 2011
Messages
245
Hi,


I found the below code posted by Fluff. I think it will allow me to do what I want mostly.

However I want the user to be able to select the file and not have link within the file. Is this achievable?

PHP:
Sub CopyPasteData()

    Dim wb As Workbook
    Dim UsdRws As Long
    Dim FilePth As String
    
Application.CutCopyMode = False
Application.ScreenUpdating = False
Application.DisplayAlerts = False


    FilePth = "d:\xxxx\xxx\xxxx\xxx.xlsx"
    Set wb = Application.Workbooks.Open(FilePth)
    UsdRws = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    wb.ActiveSheet.Range("A2:C" & UsdRws).Copy Destination:=ThisWorkbook.Worksheets(2).Range("A4")
    wb.ActiveSheet.Range("D2:E" & UsdRws).Copy Destination:=ThisWorkbook.Worksheets(2).Range("E4")
    wb.Close False
    Set wb = Nothing

Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.CutCopyMode = False

End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Replace where you have the fixed value for FilePth with

Code:
FilePth = ""
    '=============================
    'Ask for the name of the file.
    '=============================
    FilePth = Application _
      .GetOpenFilename("Excel Files (*.xlsx), *.xlsx", , ThisWorkbook.Name & " - Get Excel File")
    If FilePth <> "" Then
        MsgBox FilePth
    End If
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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