Specify a File Path from a Master Sheet

Yellow Snow

New Member
Joined
Jul 16, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

Just wondering how I could:

1. Specify a file path location in the below code from a specific cell from a "master sheet" tab.
2. Copy data formats from the source and retain the format in the destination paste location.



Sub Another_Possibility()

Dim wb1 As Workbook, wb2 As Workbook, i As Long
Dim frFile, rngArray
Application.ScreenUpdating = False
Set wb1 = ActiveWorkbook
rngArray = Array("D10", "D16:D26", "D31:D41", "J10", "J16:J26", "J31:J41", "P10", "P16:P26", "P31:P41", "V10", "V16:V26", "V31:V41")

frFile = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select file to copy from")
If frFile = False Then Exit Sub

Set wb2 = Workbooks.Open(frFile)

For i = LBound(rngArray) To UBound(rngArray)
wb1.Sheets("Sheet3").Range(rngArray(i)).Value = wb2.Sheets("Sheet1").Range(rngArray(i)).Value
Next i

wb2.Close SaveChanges:=False

Set wb2 = Nothing
Set wb1 = Nothing
Application.ScreenUpdating = True

End Sub
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,214,626
Messages
6,120,602
Members
448,974
Latest member
ChristineC

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