VBA Code to Summarize Data with Pivot Table in Excel

This code creates a pivot table with the selected range and places it in a new worksheet.

VBA Code:

Sub CreatePivotTable()
    Dim sourceData As Range
    Dim pivotTable As PivotTable
    Dim pivotSheet As Worksheet
    Set sourceData = Selection
    Set pivotSheet = Worksheets.Add
    Set pivotTable = pivotSheet.PivotTableWizard(sourceData, TableDestination:=pivotSheet.Range("A1"))
End Sub
Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group

Leave a Comment