I'm trying to work out how to copy some specific sheets from multiple files into 1 master workbook.

I have stumbled across this code https://excel.tips.net/T007425_Combi...Workbooks.html

Sub CombineSheets()
    Dim sPath As String
    Dim sFname As String
    Dim wBk As Workbook
    Dim wSht As Variant

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    sPath = InputBox("Enter a full path to workbooks")
    ChDir sPath
    sFname = InputBox("Enter a filename pattern")
    sFname = Dir(sPath & "\" & sFname & ".xl*", vbNormal)
    wSht = InputBox("Enter a worksheet name to copy")
    Do Until sFname = ""
        Set wBk = Workbooks.Open(sFname)
        Windows(sFname).Activate
        Sheets(wSht).Copy Before:=ThisWorkbook.Sheets(1)
        wBk.Close False
        sFname = Dir()
    Loop
    ActiveWorkbook.Save
    Application.EnableEvents = True
    Application.ScreenUpdating = True
End Sub
But my knowledge of VBA is rudimentary at best

The problem I have is 2 fold:

  1. The worksheets are named slightly differently in each file.

    Each book contains 4 sheets, the sheets themselves are almost identical in name except that the sheet position forms part of the name, and the position is random. i.e. in 1 book I could have A_1, B_2, and C_3 but in another it could be A_1, C_2, B_3

    Assuming I wanted to move every tab named A_ I am presuming I could simply use a wildcard like * to fill in the variable bit.

    I also have a couple of files working to a slightly different naming sttructure, i.e. a instead of A

    So I need to reference both filename partss in the code
  2. I want to rename the tabs as I copy them

    As I said above, the sheets all have the same name (near as damn it) - I don't want to end up with a workbook ful of sheets A, A, A, A, a, A etc. However, the filenames of the workbooks these sheets are in are suitable for the new tab names.





So basically I would like it to search a specific folder (this can be hard coded or requested via an entry box - I prefer hard coding.
The folder will only contain target data, so searching for *.xls should be ok.
I then want to import *A* or *a* (depending on the file type) from these old files to the new files, changing the tab name from "A" or "a" to Fn1