![]() |
Using SQL (with a Group by function) inside EXCEL VBA
Hi,
I have some data on a worksheet. I would like to use this data as input into a SQL query (Select .... from Sheet1....group by....) and load the query output on a different worksheet. How can I set up a Excel VBA macro with a SQL that will allow me to do this? -- |
Using SQL (with a Group by function) inside EXCEL VBA
It seem like you know SQL pretty well. You have afew choices. Depending on the number of items you are returning your can setup a SQL with multiple WHERE clauses to return all the items at one time or retrieve the data multiple times with a single WBERE clause. there arre two questions that need to be answered 1) Do you wnat to have the query automatically update? 2) Are the number of rows that are going to be returned each time the data is retrieve the same number of rows or are the number of rows returned going to be different each time the data is retrieved? You can get data from a database using a query or opening the database as a recordset like you would in Access. The recordset commands in Excel VBA and Access VBA are the same as is probably the better method is the number of rows going to be different each time the query is run. the disadvantage with the recordset is you would have to manually run the update or setup a timer to run the macro periodically. You can alos use a workbook open event to retrieve the data as another option. I think you need to think about which options you want before you ask for the correct code to impliment the options you choose. -- joel ------------------------------------------------------------------------ joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229 View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153331 Microsoft Office Help |
All times are GMT +1. The time now is 09:42 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com