Results 1 to 6 of 6
  1. #1
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368

    export table to multiple sheets

    Hi everyone,

    Currently I am charged with the task of writing a table containing a query results into Excel. The requirement is that each sheet can only contain 1000 records.



    Now, in VBA I can create an excel book, sheet, name it, write to it, and save it. However, the closest I've come to writing to multiple sheets is using a counter that increments after every row and once it hits 1000, to create a new sheet. This is where I get stuck. I cant seem to get the rest to populate on the new sheet. This is something I should have in my stock VBA repetoir but I dont. Could anyone please provide?

    Thank you

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by TheShabz View Post

    Now, in VBA I can create an excel book, sheet, name it, write to it, and save it. However, the closest I've come to writing to multiple sheets is using a counter that increments after every row and once it hits 1000, to create a new sheet. This is where I get stuck. I cant seem to get the rest to populate on the new sheet.
    how do you write the first 1000 recs to the first sheet? you said you can get that far. if so, then the rest is easy. you say you get stuck after the increment hits 1000. WHAT are stuck on? WHAT can't you do? copy the data using code from one app to the other? get the focus to the new sheet? what does "THE REST" mean? the rest of what?

    specificity is the key to getting help here.

  3. #3
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    wow thanks for pointing it out. Totally lost my train of thought mid sentence. The issue I'm having is creating the next sheet then having it continue populating the next sheet. Currently, it still continues to populate the first sheet. I assume I'm not pointing it to the second sheet properly.

    Thanks.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by TheShabz View Post
    wow thanks for pointing it out. Totally lost my train of thought mid sentence. The issue I'm having is creating the next sheet then having it continue populating the next sheet. Currently, it still continues to populate the first sheet. I assume I'm not pointing it to the second sheet properly.

    Thanks.
    there's alot to be learned in excel simply by recording yourself. go into excel, start recording a macro_add a new sheet by clicking the plus sign at the button_rename it by clicking and typing the new name if you want this step_then click on cell a1 in the new sheet. stop recording and read the code produced by the program. i'm sure you're good enough at that point to do the minimal translation it takes to float it on over to the access app and make it work!

  5. #5
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I went ahead and created the macro and looked at the code. I found that .select was being used to accomplish this. however, using that I am still getting the same issue in my vba code.
    This:
    Code:
     
    Set xls = xlw.worksheets.Add
    xls.Name = "Page" & pageNum
    xls.select
    is not getting the job done.

    On a side note, I'm noticing that the sheets are added to the left of each existing sheet. How would I make it go the other way. For example, currently:

    Sheet1
    Sheet2 Sheet1
    Sheet3 Sheet2 Sheet1

    I want:

    Sheet1
    Sheet1 Sheet2
    Sheet1 Sheet2 Sheet3

    Thanks again.

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I figured out what I was doing wrong. One of those that makes sense to human logic but not to programming logic. Loop issues.

    and in case anyone else was wondering how to get the sheets going the proper way, here you go:

    Code:
     
    ActiveSheet.Move After:=Sheets(ActiveWorkbook.Sheets.Count)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Form fields export to local table
    By lupis in forum Forms
    Replies: 0
    Last Post: 03-23-2010, 02:38 PM
  2. Export Access Pivot Table to Excel
    By graviz in forum Programming
    Replies: 1
    Last Post: 11-13-2009, 07:30 AM
  3. Pivot table graph form export to powerpoint
    By maati1980 in forum Forms
    Replies: 0
    Last Post: 10-22-2009, 02:59 AM
  4. export report to multiple tabs
    By mws5872 in forum Import/Export Data
    Replies: 0
    Last Post: 06-30-2009, 03:07 PM
  5. export to multiple sheets based on change in sort
    By mws5872 in forum Programming
    Replies: 0
    Last Post: 06-30-2009, 07:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums