using an inputbox to open a file and copy worksheets to another file

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
140
Office Version
  1. 365
  2. 2019
I have been all over the place with this one. What I'm looking for is a small piece of code to do the following. I get a monthly file with the turnover from departments from multiple states. I the files are stored on the Y:drive Every month the send the file in with a slightly different name example. Jan16 or January 2017 or 010117. I have tried a variety of things and decided it would be better if I could just use an inputbox to select the file, open the file, copy the four sheets i need from that file into the Master Rentention file (Ohio, Arkansas, Tennessee, and Texas) I don't mind the manual process but i have someone who puts the data together for me when I'm not available and (trust me) they need a button to click. Any thoughts? Your help is greatly appreciated.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How about
Code:
Sub OpenFile()

    Dim Fname As String
    Dim Wbk As Workbook
    
    Fname = Application.GetOpenFilename(FileFilter:="xls Files (*.xls*), *.xls*", Title:="Select a file", MultiSelect:=False)
    If Fname = "False" Then
        MsgBox "no file selected"
        Exit Sub
    Else
        Set Wbk = Workbooks.Open(Fname)
        Wbk.Sheets(Array("Sheet1", "sheet2", "sheet3")).Copy before:=ThisWorkbook.Sheets(1)
        Wbk.Close , False
    End If
End Sub
This needs to go in the Master retention workbook.
 
Upvote 0
That was perfect thanks. Sometimes i make things far more complicated than it should be.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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