Rachel,
I think this code will do what you want - Paste both the procedure &
function in a standard module. The worksheet which stores your data must have
Column headings otherwise code may fail.
Sub FilterDataToSheets()
Dim ws1 As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim lr As Integer
Dim c As Range
'worksheet where your data is stored
'change Sheet1 name as required
Set ws1 = ThisWorkbook.Worksheets("Sheet1")
With ws1
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
Set rng = .Range("A1

" & lr)
'extract list
.Columns("A:A").AdvancedFilter _
Action:=xlFilterCopy, _
CopyToRange:=.Range("J1"), Unique:=True
lr = .Cells(.Rows.Count, "J").End(xlUp).Row
'set up Criteria Area
.Range("L1").Value = .Range("A1").Value
For Each c In .Range("J2:J" & lr)
'add the name to the criteria area
.Range("L2").Value = c.Value
'sheet aleady exists
If SheetExists(c.Value) Then
Sheets(c.Value).Cells.Clear
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("L1:L2"), _
CopyToRange:=Sheets(c.Value).Range("A1"), _
Unique:=False
Else
'add new sheet and run advanced filter
Set wsNew = Sheets.Add
wsNew.Move After:=Worksheets(Worksheets.Count)
wsNew.Name = c.Value
rng.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=.Range("L1:L2"), _
CopyToRange:=wsNew.Range("A1"), _
Unique:=False
End If
Next
.Select
.Columns("J:L").Delete
End With
End Sub
Function SheetExists(wksName As String) As Boolean
On Error Resume Next
SheetExists = CBool(Len(Worksheets(wksName).Name) > 0)
End Function
jb
"Rachel" wrote:
> Help on a macro code please.
>
> Have a worksheet such as below:
>
> A B C D
> GLASS 1 YES DONE
> CUP 2 NO IN PROGRESS
> CHAIR 3 NO DONE
> CUP 4 NO IN PROGRESS
> GLASS 5 YES DONE
>
> I want to have a macro to copy the entire row to a new worksheet such that
> if COLUMN A contains the word "GLASS" it will copy the entire row to
> worksheet named "GLASS" and "CUP" to a new worksheet named "CUP" and so on
> and so fort... can this be done? THANKS!