PDA

View Full Version : Copy data from user selected source file to current open workbook



Marsau
10-28-2022, 08:58 PM
Hi there

Many videos and forum samples gives examples of letting users select there own source file for copying one simple range......but I am trying to do the following:

Aim
1. Let user select source file and export to current opened workbook with multiple ranges
2. Export ranges given to new file location as paste special values
All file has the exact sheets and exact cells


Data
source file(user selected) copy range:
1. Sheet9 (U4).current region to current opened file Sheet6 (C6).current region
2. Sheet1 (O3).current region to current opened file sheet3 (C6).current region
3. Sheet68 (E72:E91,E6:E26,G5,G6,G9,,G11,G13,G17,G18,G26) to current opened file sheet68 (E72:E91,E6:E26,G5,G6,G9,,G11,G13,G17,G18,G26)

I looked at various codes to start with and decided to use this sample to start with



Sub Get_Data_From_File()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:E20").Copy
ThisWorkbook.Worksheets("SelectFile").Range("A10").PasteSpecial xlPasteValues
OpenBook.Close False
End If
Application.ScreenUpdating = True
End Sub



But no matter how I tried to use this and incorprate what I need...I just couldnt make it work

Please help