Not sure about "Table"....
If you upload a sample with the result that you want, it would help to understand.
Sub test()
Dim a, tbl, i As Long, ii As Long, iii As Long
Dim myMethod As String, ws As Worksheet
Dim dic As Object, e, RegX As Object, m As Object
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name <> "Accession" Then ws.Delete
Next
Application.DisplayAlerts = True
Set dic = CreateObject("Scripting.Dictionary")
Set RegX = CreateObject("VBScript.RegExp")
With Sheets("accession")
tbl = .[g1].CurrentRegion.Value
With .Cells(1).CurrentRegion
a = .Value
For i = 2 To UBound(tbl, 1)
dic(tbl(i, 1)) = Empty
Next
With RegX
.Global = True: .IgnoreCase = True
.Pattern = "_([" & Join(dic.keys, "") & "])(?=(_|$))"
End With
For ii = 1 To UBound(a, 1)
If a(ii, 1) = "Check_Tray" Then
For Each e In dic
GetRows dic, e, .Rows(ii)
Next
ElseIf RegX.test(a(ii, 1)) Then
For Each m In RegX.Execute(a(ii, 1))
myMethod = m.submatches(0)
If Not IsSheetExists(myMethod) Then
Sheets.Add(after:=Sheets(Sheets.Count)).Name = myMethod
End If
GetRows dic, myMethod, .Rows(ii)
Next
Else
For i = 2 To UBound(tbl, 1)
If RegX.test(a(ii, 1)) Then
For Each m In RegX.Execute(a(ii, 1))
GetRows dic, m.submatches(0), .Rows(ii)
Next
Else
For iii = 2 To UBound(tbl, 2)
If a(ii, 1) = tbl(i, iii) Then
GetRows dic, tbl(i, 1), .Rows(ii)
Exit For
End If
Next
End If
Next
End If
Next
End With
End With
For Each e In dic
If IsSheetExists(e) Then
Sheets(e).Cells.Clear
If Not IsEmpty(dic(e)) Then dic(e).Copy Sheets(e).Cells(1)
Sheets(e).Columns.AutoFit
End If
Next
Application.ScreenUpdating = True
End Sub
Private Sub GetRows(dic As Object, ByVal myMethod As String, r As Range)
If IsEmpty(dic(myMethod)) Then
Set dic(myMethod) = r
Else
Set dic(myMethod) = Union(dic(myMethod), r)
End If
End Sub
Function IsSheetExists(ByVal txt As String) As Boolean
On Error Resume Next
IsSheetExists = Len(Sheets(txt).Name)
On Error GoTo 0
End Function
Edit:
Bookmarks