Windows Vista Forums

Reading SQL Table into Excel and calculating/inserting group line (with VBA)?

  1. #1


    Claudia d'Amato Guest

    Reading SQL Table into Excel and calculating/inserting group line (with VBA)?

    Assume I have in a SQL database (Oracle) a table like:

    Group Name value1 value2
    1 Karl 10 20
    1 Paul 3 4
    2 Tony 2 0
    2 Ben 80 100
    2 Peter 1 1
    3 ....

    Now I want to read this table with VBA and insert it into an Excel sheet.



    Moreover after each group a sum line should be calculated and inserted so that the Excel sheet
    should look like:

    G name V1 V2
    1 Karl 10 20
    1 Paul 3 4
    1 sum 13 24
    2 Tony 2 0
    2 Ben 80 100
    2 Peter 1 1
    2 sum 83 101
    3 ....
    ....

    How can I code this in VBA ?

    Claudia


      My System SpecsSystem Spec

  2. #2


    Bob Phillips Guest

    Re: Reading SQL Table into Excel and calculating/inserting group line (with VBA)?

    Just drop the recordset into a worksheet using CopyFromRecordset and the
    just use Data>Subtotals breaking on the group name.

    --
    __________________________________
    HTH

    Bob

    "Claudia d'Amato" <clauama@xxxxxx> wrote in message
    news:4969c761$0$31872$9b4e6d93@xxxxxx-online.net...

    > Assume I have in a SQL database (Oracle) a table like:
    >
    > Group Name value1 value2
    > 1 Karl 10 20
    > 1 Paul 3 4
    > 2 Tony 2 0
    > 2 Ben 80 100
    > 2 Peter 1 1
    > 3 ....
    >
    > Now I want to read this table with VBA and insert it into an Excel sheet.
    >
    > Moreover after each group a sum line should be calculated and inserted so
    > that the Excel sheet
    > should look like:
    >
    > G name V1 V2
    > 1 Karl 10 20
    > 1 Paul 3 4
    > 1 sum 13 24
    > 2 Tony 2 0
    > 2 Ben 80 100
    > 2 Peter 1 1
    > 2 sum 83 101
    > 3 ....
    > ...
    >
    > How can I code this in VBA ?
    >
    > Claudia
    >


      My System SpecsSystem Spec

Reading SQL Table into Excel and calculating/inserting group line (with VBA)?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error when updating Access table from Excel Worksheet Glenn VB Script 1 09 Aug 2009
Inserting Attachment from Excel Anne O'Connor Vista mail 13 09 May 2009
Exporting MsSQL table to Excel using vbScript? StephaneLeFou VB Script 0 19 Mar 2009
Free stuff: The Excel color index as table Benny Pedersen VB Script 0 08 Mar 2009
dynamic table excel 2007? Ricardo Vista General 1 20 Oct 2007