Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

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

Reply
 
Old 01-11-2009   #1 (permalink)
Claudia d'Amato


 
 

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
Old 01-11-2009   #2 (permalink)
Bob Phillips


 
 

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...
Quote:

> 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
Reply

Thread Tools


Similar Threads
Thread Forum
Error when updating Access table from Excel Worksheet VB Script
Inserting Attachment from Excel Vista mail
Exporting MsSQL table to Excel using vbScript? VB Script
Free stuff: The Excel color index as table VB Script
dynamic table excel 2007? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46