2016年10月3日 星期一

Excel-多個分頁合併

將多個分頁合併成一個檔
sheet1、sheet2....等
合併成Combine


Sub Combine()
    Dim J As Integer
    On Error Resume Next
    Sheets(1).Select
    Worksheets.Add
    Sheets(1).Name = "Combine"
    Sheets(2).Activate
    Range("A1").EntireRow.Select
    Selection.Copy Destination:=Sheets(1).Range("A1")

    For J = 2 To Sheets.Count
        Sheets(J).Activate
        If Range("K12").Value = "AA" Then '判斷欄位是否為AA
            Range("H22").Select '表格開始位置
            Selection.CurrentRegion.Select
            Selection.Offset(1, 0).Resize(Selection.Rows.Count - 1).Select
            Selection.Copy Destination:=Sheets(1).Range("A65536").End(xlUp)(2)
        End If
    Next
End Sub