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

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88
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.
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,116
Office Version
  1. 365
Platform
  1. Windows
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.
 

rholdren

Board Regular
Joined
Aug 25, 2016
Messages
88
That was perfect thanks. Sometimes i make things far more complicated than it should be.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
53,116
Office Version
  1. 365
Platform
  1. Windows
Glad to help & thanks for the feedback
 

Watch MrExcel Video

Forum statistics

Threads
1,122,914
Messages
5,598,840
Members
414,261
Latest member
KatieBsc

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
Top