Private Sub CommandButton1_Click()
Dim eachsht As Worksheet, eachrng As Range, tmpTbl As Range
For Each eachsht In Worksheets
If eachsht.Name <> "Statement" Then
Set eachrng = Sheets("Statement").Range("a65536").End(xlUp).Offset(1)
Set tmpTbl = eachsht.Range("a2").CurrentRegion
eachsht.Range("a2").CurrentRegion.AutoFilter Field:=3, Criteria1:=Sheets("Statement").Range("G2"), Operator:=xlAnd
tmpTbl.Rows("2:" & tmpTbl.Rows.Count).Copy eachrng
End If
Next
End Sub
當乎合條件的要求, 例如 "AA Ltd" 條件都在 Jan , Feb. Mar Sheet - 資料表出現的話, 這巨集就能正確篩選所需的資料及複製到Statement Sheet.
Sub Click()
Dim eachsht As Worksheet, eachrng As Range, tmpTbl As Range
Dim myFld As Integer, I As Integer, Q As Range
For Each eachsht In Worksheets
If eachsht.Name <> "Statement" Then
Set eachrng = Sheets("Statement").Range("a65536").End(xlUp).Offset(1)
Set tmpTbl = eachsht.Range("a2").CurrentRegion
Set Q = Sheets("Statement").Range("G2")
myFld = 3
For I = 2 To 180
If tmpTbl.Cells(I, myFld).Value = Q Then
eachsht.Range("a2").CurrentRegion.AutoFilter Field:=3, Criteria1:=Q, Operator:=xlAnd
tmpTbl.Rows("2:" & tmpTbl.Rows.Count).Copy eachrng
End If
Next