Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Query's

  1. #1
    Guest

    Default

    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. #2
    BatCoder
    Join Date
    Feb 2002
    Location
    Turkey
    Posts
    813
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

    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. #3
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Austin, Texas USA
    Posts
    11,654
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-03-14 07:03, Anonymous wrote:
    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?
    Yes, using the Data | Get External Data menu command.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •