Visual Basic and Pivot table

chociao

New member
Joined
Sep 21, 2009
Messages
1
Programming Experience
1-3
hello there,

I am new to this forum and i need help with my code.
I have a code that grabs data from sql server fine. it spits the data into an excel table.

what i am trying to do is, i want to create a pivot table with the data. here is what i have:

VB.NET:
Private Sub createPivotTable()
        Dim shtDestination As Microsoft.Office.Interop.Excel.Worksheet

        shtDestination = activeworksheet

        Dim wbkTemplate As Microsoft.Office.Interop.Excel.Workbook

        wbkTemplate = Microsoft.Office.Interop.Excel.Workbooks.Open("") '-> i cant use open as the data that i am getting is with in the script

        Dim shtSrc As Microsoft.Office.Interop.Excel.Worksheet

        shtSrc = wbkTemplate.Sheets(1)

        Dim ptSrc As Microsoft.Office.Interop.Excel.PivotTable

        ptSrc = shtSrc.PivotTables(1)

        ptSrc.TableRange2.Select()

        Application.Selection.Copy()

        shtDestination.Paste()

        wbkTemplate.Close(False)

    End Sub

so basicall when i have my data, all i want is create a pivot table by seleccting all the worksheet, and do simple pivot table calculation interms of count or sum of he columns.

many thanks for the response
 
Back
Top