VB Code top open file from specific folder and copy from specific sheet

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
Dear Sir,
I need VB code to work following way;
I will link it with a button, when we click it, it should open following path;
Thisworkbook.path/Backup/

User select an excel file, the folder has many excel workbooks.xlsb with different names
All workbooks do have sheet named "Layout" so when user select any of worksbook, the following should be copied to "Activesheet"
Copied from "Selected workbook - Worksheet: Layout - Range B6:Q498"
Paste to "Activeworksheet - Range: B6:Q498"
It should paste same format, formula and everything same way
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Not sure this is what you are looking for, but you can test it and see.

Code:
Sub t()
Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
fPath = "ThisWorkbook.Path\Backup\"
fName = Application.GetOpenFilename("Excel Files (" & fPath & "*.xlsb)," & fPath & "*.xlsb")
Set wb = Workbooks.Open(fName)
wb.Sheets("Layout").Range("B6:Q498").Copy sh.Range("B6")
wb.Close False
End Sub
 
Upvote 0
Dear Sir
Thanks a lot, this worked perfect, I also need one more help, can we join these two codes together?
Code:
Sub Copied()sc = Sheets.Count
    sn = ActiveSheet.Name
    For sh = 1 To sc
        If Sheets(sh).Name = sn Then
            ns = sh + 1
            If ns > sc Then ns = 1
            Sheets(ns).Visible = -1
            Sheets(sh).Visible = 2
        End If
    Next sh
    
Dim rng As Range, r%
[A5:A498].EntireRow.Hidden = True
Set rng = [A5:A6]
For r = 9 To 498 Step 4
    Set rng = Union(rng, Cells(r, 1).Resize(2))
Next
rng.EntireRow.Hidden = False


Dim sh As Worksheet, fPath As String, fName As String
Set sh = ActiveSheet
fPath = "ThisWorkbook.Path\Backup\"
fName = Application.GetOpenFilename("Excel Files (" & fPath & "*.xlsb)," & fPath & "*.xlsb")
Set wb = Workbooks.Open(fName)
wb.Sheets("Layout").Range("B6:Q498").Copy sh.Range("B6")
wb.Close False


End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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