Sub 피벗생성()

    Dim 피벗캐시 As PivotCache
    Dim 피벗 As PivotTable

    Sheets.Add
    
    Set 피벗캐시 = ThisWorkbook.PivotCaches.Create( _
                    SourceType:=xlDatabase, _
                    SourceData:=Sheets("sample").Range("A1").CurrentRegion)
                   
    Set 피벗 = 피벗캐시.CreatePivotTable(TableDestination:=Range("A3"))
                        
    With 피벗.PivotFields("지역")
        .Orientation = xlRowField
        .Position = 1
    End With
    
    With 피벗.PivotFields("지점")
        .Orientation = xlRowField
        .Position = 2
    End With
    
    With 피벗.PivotFields("월")
        .Orientation = xlColumnField
        .Position = 1
    End With
    
    피벗.AddDataField 피벗.PivotFields("판매액"), "합계 : 판매액", xlSum
    
    피벗.PivotFields("지역").PivotItems("서울").Position = 1
    
    With 피벗.PivotFields("합계 : 판매액")
        .Caption = "매출"
        .NumberFormat = "#,##0_ "
    End With
    
End Sub