Advertisement

07.19.2008 at 01:58PM PDT, ID: 23579437
[x]
Attachment Details

Place result of one excel query on multiple worksheets (over 65536 records)

Asked by atprato in Microsoft Excel Spreadsheet Software

Tags: VBA, Excel

I use VBA in Excel to query data directly into a worksheet.  Recently some of my query's have resulted in over 65536 records.  Can I add some language to my VBA query so that records overflow to the next worksheet or a specified worksheet?  (May need about 4 worksheets in some cases).  Start Free Trial
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:
Sub Query() 
    
    Sheets("Property").Activate 
    Dim com, Workbook, Server, UID, PWD, DSheet, Year, Month, PCN, Port, SSelect, Where, SFrom As String 
    Workbook = ThisWorkbook.Name 
    UID = Range("b1") 
    PWD = Range("b2") 
    Database = Range("b3") 
    Server = Range("b4") 
    DSheet = Range("b5") 
    SSelect = Range("b7") 
    SFrom = Range("b8") 
    SWhere = Range("b9") 
    SORDER = Range("b10") 
    SGroup = Range("b11") 
    StartRange = Range("b6") 
    
    Sheets(DSheet).Select 
    Cells.Delete 
    With ActiveSheet.QueryTables.Add(Connection:="ODBC; _
    DRIVER={iSeries Access ODBC Driver}; _ 
    SYSTEM=" & Server & ";UID=" & UID & ";PWD=" & PWD & ";DBQ=" _
    & Database & ";", _ 
    Destination:=Sheets(DSheet).Range(StartRange)) 
        .Sql = SSelect & " " & SFrom & " " & SWhere & " " & _
        SORDER & " " & SGroup 
        '.PostText = True 
        .FieldNames = True 
        .RefreshStyle = xlOverwriteCells 
        .RowNumbers = False 
        .FillAdjacentFormulas = False 
        .RefreshOnFileOpen = False 
        .HasAutoFormat = False 
        .BackgroundQuery = True 
        .SavePassword = True 
        .SaveData = True 
        .Refresh False 
    End With 
End Sub
[+][-]07.19.2008 at 11:20PM PDT, ID: 22044730

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 06:29AM PDT, ID: 22045737

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 08:23AM PDT, ID: 22046035

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 05:00PM PDT, ID: 22047471

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 06:49PM PDT, ID: 22047669

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.20.2008 at 09:03PM PDT, ID: 22047975

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Excel Spreadsheet Software
Tags: VBA, Excel
Sign Up Now!
Solution Provided By: atprato
Participating Experts: 1
Solution Grade: A
 
 
[+][-]07.21.2008 at 05:46AM PDT, ID: 22049932

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628