Function IsInArray(stringToBeFound As String, arr As Variant) As Long
Dim i As Long
' default return value if value not found in array
IsInArray = -1
For i = LBound(arr) To UBound(arr)
If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then
IsInArray = i
Exit For
End If
Next i
End Function
Sub test()
Dim shnames As Variant
Dim sh As Worksheet
Dim oWB As Workbook
Dim nWB As Workbook
Dim x As Integer
Dim getname As String
shnames = Split("H21 Sales Upload,H21 Rental Upload,Anchor Upload,Girlings Upload,McStone Upload,RHS Upload,RM Upload", ",")
Set oWB = ThisWorkbook
Workbooks.Add
Set nWB = ActiveWorkbook
x = 1
For Each sh In oWB.Sheets
If IsInArray(sh.Name, shnames) > -1 Then
getname = sh.Name
sh.Cells.Copy
If x = 1 Then
nWB.Sheets(x).Name = getname
nWB.Sheets(x).Range("A1").PasteSpecial xlPasteValues
nWB.Sheets(x).Range("A1").PasteSpecial xlPasteFormats
x = x + 1
Else
nWB.Sheets.Add after:=nWB.Worksheets(Worksheets.Count)
nWB.Sheets(x).Name = getname
nWB.Sheets(x).Range("A1").PasteSpecial xlPasteValues
nWB.Sheets(x).Range("A1").PasteSpecial xlPasteFormats
x = x + 1
End If
End If
Next sh
Application.CutCopyMode = False
End Sub