![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Guest
Posts: n/a
|
Is it possible when getting external data in to Excel, to run multiple query's that load data on to individual worksheets of 1 workbook?
|
|
|
|
#2 |
|
BatCoder
Join Date: Feb 2002
Location: Turkey
Posts: 764
|
You can use DAO to get data by SQL strings easily.
'This routine opens sample.xls file then uses the sqlstr string as SQL text then retrieves data by given criteria. You can create multiply queries with this way. Sub GetData() 'Reference : DAO 3.6 object library Dim dbmain As Database Dim rcset As Recordset Dim sqlstr As String Dim i As Integer Set dbmain = OpenDatabase("c:windowsdesktopsample.xls", False, False, "Excel 8.0;") sqlstr = "SELECT * FROM [Jan2002$] WHERE Code<100000" Set rcset = dbmain.OpenRecordset(sqlstr) Do Until rcset.EOF i = i + 1 ActiveSheet.Cells(i, 1).Value = rcset.Fields(1).Value ActiveSheet.Cells(i, 2).Value = rcset.Fields(2).Value rcset.MoveNext Loop Set rcset = Nothing Set dbmain = Nothing End Sub regards Suat (You can visit TheWordExpert for VBA help and also other office applications) |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Austin, Texas USA
Posts: 11,654
|
Quote:
|
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|