Sub LM_Test()
Dim wksSht As Worksheet
Dim wbkTemp As Workbook
Dim vararrShtType() As Variant
Dim vararrSht() As Variant
Dim lngLoop As Long
Dim lngLoop1 As Long
Dim lngCount As Long
'Populating sheet types in an array
vararrShtType = Array("Fin_", "Hr_")
'Redimenson array
ReDim vararrSht(1 To UBound(vararrShtType) + 1, 1 To ThisWorkbook.Worksheets.Count)
'Looping through each sheet
lngCount = 0
For Each wksSht In ThisWorkbook.Worksheets
For lngLoop = LBound(vararrShtType) To UBound(vararrShtType)
If Left(LCase(wksSht.Name), Len(vararrShtType(lngLoop))) = LCase(vararrShtType(lngLoop)) Then
lngCount = lngCount + 1
vararrSht(lngLoop + 1, lngCount) = wksSht.Name
End If
Next lngLoop
Next wksSht
'Looping for sheets to combined it in a single workbook
For lngLoop = LBound(vararrSht) To UBound(vararrSht)
Set wbkTemp = Nothing
For lngLoop1 = LBound(vararrSht) To UBound(vararrSht, 2)
If LenB(Trim(vararrSht(lngLoop, lngLoop1))) > 0 Then
'Adding new workbook
If wbkTemp Is Nothing Then
Set wbkTemp = Workbooks.Add(1)
End If
'Copying sheets to new workbook
ThisWorkbook.Worksheets(vararrSht(lngLoop, lngLoop1)).Copy After:=wbkTemp.Sheets(wbkTemp.Sheets.Count)
End If
Next lngLoop1
If Not wbkTemp Is Nothing Then
'Saving workbook
wbkTemp.SaveAs ThisWorkbook.Path & Application.PathSeparator & vararrShtType(lngLoop - 1) & ".xlsx", 51
End If
'Closing workbook
If Not wbkTemp Is Nothing Then wbkTemp.Close 1
Set wbkTemp = Nothing
Next lngLoop
'Releasing memory
Set wksSht = Nothing
Set wbkTemp = Nothing
Erase vararrShtType
Erase vararrSht
lngLoop = Empty
lngLoop1 = Empty
lngCount = Empty
End Sub