Wednesday, 7 December 2016

EXCEL MACRO TO CONSOLIDATE MULTIPLE SHEETS AND CREATE PIVOT

Sub RAGHU()
'
' RAGHU Macro
'

'
    Sheets("Sandeep").Select
    Range("A1:z200").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
   
    Sheets("Ashwin").Select
    Range("A25:z200").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    Worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
    ActiveSheet.Paste
    Sheets("Raja").Select
    Range("A5:z200").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Sheet1").Select
    Worksheets("sheet1").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
    ActiveSheet.Paste
    Worksheets("Sheet1").Range("A1:z200").Columns.AutoFit
   
    Columns("A:S").Select
    Range("A2").Activate
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R2C1:R1048576C19", Version:=xlPivotTableVersion15).CreatePivotTable _
        TableDestination:="Sheet4!R3C1", TableName:="PivotTable3", DefaultVersion _
        :=xlPivotTableVersion15
    Sheets("Sheet4").Select
    Cells(3, 1).Select
    ActiveWorkbook.SlicerCaches.Add2(ActiveSheet.PivotTables("PivotTable3"), _
        "Owner").Slicers.Add ActiveSheet, , "Owner 1", "Owner", 79.5, 334.5, 144, _
        198.75
    ActiveSheet.Shapes.Range(Array("Owner 1")).Select
    Range("B8").Select
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Cust")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Requirement")
        .Orientation = xlRowField
        .Position = 2
    End With
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("No of positions"), "Count of No of positions", _
        xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("No of CV Sourced"), "Count of No of CV Sourced", _
        xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Shortlisted"), "Count of Shortlisted", xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("f2f Interview"), "Count of f2f Interview", xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Selected"), "Count of Selected", xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Offered"), "Count of Offered", xlCount
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Status of Position")
        .Orientation = xlPageField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Joined"), "Count of Joined", xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Yet to join"), "Count of Yet to join", xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Offer Declined"), "Count of Offer Declined", _
        xlCount
    ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
        "PivotTable3").PivotFields("Open Postions"), "Count of Open Postions", xlCount
    With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "Count of No of positions")
        .Caption = "Sum of No of positions"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "Count of No of CV Sourced")
        .Caption = "Sum of No of CV Sourced"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Count of Shortlisted")
        .Caption = "Sum of Shortlisted"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "Count of f2f Interview")
        .Caption = "Sum of f2f Interview"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Count of Selected")
        .Caption = "Sum of Selected"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Count of Offered")
        .Caption = "Sum of Offered"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Count of Joined")
        .Caption = "Sum of Joined"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields("Count of Yet to join")
        .Caption = "Sum of Yet to join"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "Count of Offer Declined")
        .Caption = "Sum of Offer Declined"
        .Function = xlSum
    End With
    With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
        "Count of Open Postions")
        .Caption = "Sum of Open Postions"
        .Function = xlSum
    End With
   
End Sub


No comments:

Post a Comment

Git

1 git add ↳ It lets you add changes from the working directory into the staging area 2 git commit ↳ It lets you save a snapshot of currently...