View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Create two sheets, filter data to each

Sub SplitSheet()

Set OldSht = ActiveSheet

Set ABCSht = Sheets.Add(after:=Sheets(Sheets.Count))
ABCSht.Name = "ABC"
'copy header row
OldSht.Rows(1).Copy _
Destination:=ABCSht.Rows(1)
ABCRowCount = 2

Set DEFSht = Sheets.Add(after:=Sheets(Sheets.Count))
ABCSht.Name = "DEF"
'copy header row
OldSht.Rows(1).Copy _
Destination:=DEFSht.Rows(1)
DEFRowCount = 2

With OldSht
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
For RowCount = 2 To LastRow
ItemName = Range("A" & RowCount)
Select Case UCase(ItemName)

Case "ABC"
.Rows(RowCount).Copy _
Destination:=ABCSht.Rows(ABCRowCount)
ABCRowCount = ABCRowCount + 1
Case "DEF"
.Rows(RowCount).Copy _
Destination:=DEFSht.Rows(DEFRowCount)
DEFRowCount = DEFRowCount + 1
End Select
Next RowCount

OldSht.Delete

End With





End Sub


"J.W. Aldridge" wrote:


Sheet X has data in A:H. (No headers)
For each row with data, column A will contain either "abc" or "def".

I need to create two sheets
1 - "ABC Group"
2 - "DEF Group"

Filter all rows with abc in A to sheet ABC Group.
Filter all rows with def in A to sheet DEF Group.
Delete the original sheet - SheetX