Sub 월별부분합()
'
' 월별부분합 매크로
' 데이터 정렬 후 월별 제품종류별로 부분합
'

'
'화면갱신 방지
    Application.ScreenUpdating = False
    
    Range("A3").Select
    ActiveWorkbook.Worksheets("실적현황").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("실적현황").Sort.SortFields.Add2 Key:=Range("A4:A201") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
'코드 수정1

    ActiveWorkbook.Worksheets("실적현황").Sort.SortFields.Add2 Key:=Range(Range("정렬필드")) _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("실적현황").Sort
        .SetRange Range("A3:I201")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("B:B,F:F,H:H").Select
    Selection.EntireColumn.Hidden = True
    Range("A3").Select
    Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(7, 9), _
        Replace:=True, PageBreaks:=False, SummaryBelowData:=True
'코드 수정2

    Selection.Subtotal GroupBy:=Range("부분합필드"), Function:=xlSum, TotalList:=Array(7, 9), _
        Replace:=False, PageBreaks:=False, SummaryBelowData:=True
    ActiveSheet.Outline.ShowLevels RowLevels:=3
    Range("A3:I250").Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
    Sheets.Add After:=ActiveSheet
'코드 수정3

    ActiveSheet.Name = Range("정렬필드") & Sheets.Count - 1
    Range("A2").Select
    ActiveSheet.Paste
    Selection.Replace What:="요약", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Columns("A:F").Select
    Columns("A:F").EntireColumn.AutoFit
    Range("A1").Select
    Sheets("실적현황").Select
    Application.CutCopyMode = False
    Range("A3").Select
    Selection.RemoveSubtotal
    Columns("A:I").Select
    Selection.EntireColumn.Hidden = False
    Range("B3").Select
    ActiveWorkbook.Worksheets("실적현황").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("실적현황").Sort.SortFields.Add2 Key:=Range("B3:B201") _
        , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("실적현황").Sort
        .SetRange Range("A3:I201")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A1").Select

'화면갱신 방지 해제
    Application.ScreenUpdating = True
End Sub
