Hi All,

Im having a bit of trouble with capturing data from multiple workbook sources. In the code below, I'm pulling data from Sheet2 in workbooks located in a different directory than the workbook that the macro is stored in. This works fine, however there are some workbooks in that directory that will have the same sheet name that I want to ignore when the macro runs. Is there a way to ignore specific workbooks?

When I add
And wbD.Name <> "Ignorethisbook.xlsx"
to the
Do While sFile <> ""
line I get an error.

Any help would be greatly appreciated, thanks!

Sub WBMerge()
    ' Merges workbooks from a different directory
    
    Dim sFolder As String
    Dim sFile As String
    Dim wbD As Workbook, wbS As Workbook
     
    Application.ScreenUpdating = False
    Set wbS = ThisWorkbook
    ThisWorkbook.Sheets("Sheet1").Activate
    sFolder = "C:\Folder1\Folder2\Folder3\Folder4\"
    ThisWorkbook.Sheets("Sheet1").UsedRange.Offset(1).Clear
    sFile = Dir(sFolder & "*.xl*")

    Do While sFile <> ""
            Set wbD = Workbooks.Open(sFolder & sFile) 'open the file; add condition to
            wbD.Sheets("Sheet2").UsedRange.Offset(1, 1).Copy
            wbS.Activate
            ThisWorkbook.Sheets("Sheet1").Range("E" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
            Application.CutCopyMode = False
            wbD.Close savechanges:=False 'close without saving
            sFile = Dir 'next file
    Loop
 
    Application.ScreenUpdating = True
    
    ' Rearranage Columns to different destination then delete original
    Columns("P:P").Cut Destination:=Columns("A:A")
    Columns("L:L").Cut Destination:=Columns("Q:Q")
    Columns("J:J").Cut Destination:=Columns("R:R")
    Columns("H:H").Cut Destination:=Columns("S:S")
    Columns("K:K").Cut Destination:=Columns("T:T")
    Columns("E:E").Cut Destination:=Columns("U:U")
    Columns("F:F").Cut Destination:=Columns("V:V")
    Columns("G:G").Cut Destination:=Columns("W:W")
    Columns("I:I").Cut Destination:=Columns("X:X")
    Columns("M:M").Cut Destination:=Columns("Y:Y")
    Columns("N:N").Cut Destination:=Columns("Z:Z")
    Columns("O:O").Cut Destination:=Columns("AA:AA")
    Columns("E:P").Delete
    
End Sub