You are on page 1of 1

Assume this scenario: Workbooks(1).Sheets(1).Range("A2:A4") has a list of names.

Workbooks(2) contains five sheet and two of those sheets have names that will match
with names in sheet one of Workbooks(1). The following code would find those two
sheets and make separate workbooks for them, each workboook being named for the
sheet name. This is untested.

Sub matchMake()
Dim wb1 As Workbook, wb2 As Workbook, sh As Worksheet, fSh As Worksheet, lr As
Long, rng As Range, c As Range
Set wb1 = Workbooks(1) 'Edit wb name
Set wb2 = Workbooks(2) 'Edit wb name
Set sh = wb1.Sheets(1) 'Edit sheet name
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row 'Find last row of data in col A
Set rng = sh.Range("A2:A" & lr) 'Define the range to be evaluated
For Each c In rng 'Go dow the list of names
For Each fSh In wb2.Sheets 'Check each sheet in wb2
If fSh.Name = c.Value Then 'Compare names
fSh.Copy 'create new workbook for matches
ActiveWorkbook.SaveAs fSh.Name & ",xlsx" 'Name the new workbook
with sheet name
c.Offset(0, 1) = ActiveWorkbook.Name 'Record the new workbook in
wb1
ActiveWorkbook.Close
End If
Next
Next
End Sub

You might also like