Assuming there are only two sheets to filter to as you demonstrated, run this macro:
Option Explicit
Sub ParseSpecial()
'Author: Jerry Beaucaire, ExcelForum.com
'Date: 10/27/2010
Dim RNG As Range, SubRNG As Range
Dim a As Long, sh As Worksheet
Application.ScreenUpdating = False
'Option to clear destination sheets so all data is fresh
If MsgBox("Clear destination sheets?" & vbLf & vbLf & _
"YES - all data cleared and new data added from this sheet" & vbLf & _
"NO - data from this sheet added to the bottom of existing data", _
vbYesNo, "Clear Data?") = vbYes Then
For Each sh In Sheets(Array("SHR - JBR", "DOHA - SHR"))
sh.Cells.Clear
Next sh
End If
'insert row to separate data from headers
Rows(4).Insert xlShiftDown
'Make sure autofilter isn't on already
ActiveSheet.AutoFilterMode = False
'set the copy range
Set RNG = Range("A4:A" & Rows.Count).SpecialCells(xlConstants)
'Loop through each invoice as a section
For a = 1 To RNG.Areas.Count
With Rows(RNG.Areas(a).Cells(2, 1).Row)
'turn on autofilter in this invoice
.AutoFilter
'filter for SHR and JBR
.AutoFilter Field:=3, Criteria1:="SHR"
.AutoFilter Field:=4, Criteria1:="JBR"
'Copy to SHR - JBR sheet
If RNG.Areas(a).Cells(1).End(xlDown).Row > .Row Then _
.CurrentRegion.Copy Sheets("SHR - JBR").Range("A" & Rows.Count).End(xlUp).Offset(2)
'filter for DOHA and SHR
ActiveSheet.ShowAllData
.AutoFilter Field:=3, Criteria1:="DOHA"
.AutoFilter Field:=4, Criteria1:="SHR"
'Copy to DOHA - SHR sheet
If RNG.Areas(a).Cells(1).End(xlDown).Row > .Row Then _
.CurrentRegion.Copy Sheets("DOHA - SHR").Range("A" & Rows.Count).End(xlUp).Offset(2)
'turn off autfilter in this invoice
.AutoFilter
End With
Next a
Rows(4).Delete xlShiftUp
Application.ScreenUpdating = True
Beep
End Sub
I corrected the spelling of your DOHA - SHR sheet so that it is consistent.
I've added the macro to your sample workbook and attached it to the button seen.
Bookmarks