+ Reply to Thread
Results 1 to 3 of 3

Update query with multiple worksheets

  1. #1
    Forum Contributor
    Join Date
    02-13-2017
    Location
    Belgium
    MS-Off Ver
    O365
    Posts
    105

    Update query with multiple worksheets

    Hi All,

    I have a worksheet called "Actuals" with a query on it.
    The source behind the query is an excel file with multiple worksheets by week ex. W1, W2, W3, ...

    For example in week 3, I want to see worksheets W1, W2 and W3.
    I go to my ribbon in excel: Data > connections > properties > Definition > Command text

    There I type :

    SELECT `W1$`.*
    FROM `XXXXXXX.xlsm`.`W1$` `W1$`
    Union all
    SELECT `W2$`.*
    FROM `XXXXXXX.xlsm`.`W2$` `W2$`
    Union all
    SELECT `W3$`.*
    FROM `XXXXXXX.xlsm`.`W3$` `W3$`


    Is there a possibility to update this automatically with a macro?
    So if I push a button, another week is added.

    Thanks in advance.
    If anyone would like an example, feel free to ask.

    kr Jones

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Update query with multiple worksheets

    Here is something that uses one of my "standard" modules. I generally use this with an Oracle database, but it should also work with any data connection.

    Go to Data -> Connections and get (or change) the name of your connection.

    Copy the code into a module in your workbook. Also copy the SQL sheet into your workbook. Put the name of your connection in place of qry_data in the following code.
    Please Login or Register  to view this content.
    Enter the week number in Cell E4 on the SQL sheet. Run the NewWeek macro. This macro adds the current week SQL to the table. Cell A1, AKA "My_SQL," contains a concatenated string of the SQL commands created by the Supercat function. The subroutine SubSQL replaces the existing command string for the connection with the new SQL.

    SubSQL is a powerful tool. You can use all kinds of formulas to generate SQL "on the fly."
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  3. #3
    Forum Contributor
    Join Date
    02-13-2017
    Location
    Belgium
    MS-Off Ver
    O365
    Posts
    105

    Re: Update query with multiple worksheets

    Thanks man!

    I will try this as soon as I can.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 0
    Last Post: 05-18-2017, 06:58 PM
  2. [SOLVED] Update on multiple query formula please
    By Christopherdj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2012, 08:25 PM
  3. Update query with multiple Sets and Where conditions
    By JasonBarnes in forum Access Tables & Databases
    Replies: 3
    Last Post: 12-15-2010, 04:33 PM
  4. Update validation on multiple worksheets at once
    By sim in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-09-2010, 10:37 AM
  5. Replies: 0
    Last Post: 07-06-2006, 12:00 AM
  6. Update multiple worksheets
    By Lizz45ie in forum Excel General
    Replies: 0
    Last Post: 05-31-2005, 04:21 PM
  7. how can I update multiple worksheets at the same time
    By David2507 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2005, 03:06 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1