Here you go. A couple things:
- You'll have to change the sheet names in the first couple lines to match your actual sheet names.
- The code isn't set up to handle multiple runnings of the code. Whgat I mean is that if you run this on your example sheet, it will create 12 and 20 tabs and copy the stuff over. If you tried running it again, it would fail because it would try to create sheets that already exist. So you'd have to delete the new sheets before running again.
That last bullet is fixable if it's an issue for you. I didn't address it in the code because I don't know what you want. You could either :
- Delete the sheets each time the code is run, creating new sheets, or
- Add the results to a sheet if it already exists, otherwise create a new sheet.
Sub neilkotze()
Set ws1 = Sheets("Master Sheet")
Set ws2 = Sheets("List to loop through")
For Each Cell In ws2.Range("A2:A" & ws2.Cells(Rows.Count, "A").End(xlUp).Row)
With ws1.Range("C:Z")
Set c = .Find(Cell.Value)
If Not c Is Nothing Then
FirstAdd = c.Address
Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
ws.Name = Cell.Value
OpenRow = 1
Do
c.EntireRow.Copy ws.Rows(OpenRow)
OpenRow = OpenRow + 1
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAdd
End If
End With
Next
End Sub
Bookmarks