+ Reply to Thread
Results 1 to 10 of 10

Extend copy range of a macro in a query file

  1. #1
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Extend copy range of a macro in a query file

    In the sample sheet attached I have 2 query files, one immediately follows the other and they are both the same file and contain the same data. I have 2 macros set up to transfer data to sheet2. The HomeCopy macro transfers data from the first query table and the AwayCopy macro transfers data from the second (orange) query table. The code I'm using for the HomeCopy macro is:

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The issue I'm having is that each query table would be updated weekly and the amount of scores increased so the range in the macro "A2:U16" would no longer applicable. This range is always the total amount of rows in the query table so for example if I added 4 new scores to the query file then the required range would be "A2:U20". Is it possible to set the range as the total amount of rows in the query file so that when it was refreshed each week the macro would pick up the newly added data? I may have explained that badly, not sure.

    Thanks in advance for any replies. Sample 14 .xlsm

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extend copy range of a macro in a query file

    Try:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Re: Extend copy range of a macro in a query file

    Hi, thanks for your suggestion. This is copying all the visible data for BOTH query tables. I'm looking to copy the visible range of just the blue query table using the HomeCopy macro. The AwayCopy macro would then copy the visible data of the orange query table.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extend copy range of a macro in a query file

    Your sample doesn't show me blue or orange and it only labels "Home"???

  5. #5
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Re: Extend copy range of a macro in a query file

    Ah ok, you don't see this?

    Sample 14 SS.PNG

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extend copy range of a macro in a query file

    Hi Consty,

    I'm sorry - I first looked at this on my PC which only runs 2003 - when I downloaded to my 2010 - I got the colors. Where are you pasting the away?

    Try this:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Re: Extend copy range of a macro in a query file

    The home macro is separate from the away macro and they would never be used together. Essentially the away macro should mirror that of the home macro and would be placed into the same destination cell on sheet2 when ran. I've tried the above code and just removed the away information but have encountered a couple of issues.

    1. The header for the blue query table is being copied onto sheet2. This isn't required.
    2. If I filter a column in the blue query table and run the macro, all of the data is being copied to sheet2 and not just the filtered visible data.

    The functionality of the code in my original post is fine, it's just extending the range when I update and refresh the query file which is the issue.

  8. #8
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Re: Extend copy range of a macro in a query file

    The home macro is separate from the away macro and they would never be used together. Essentially the away macro should mirror that of the home macro and would be placed into the same destination cell on sheet2 when ran. I've tried the above code and just removed the away information but have encountered a couple of issues.

    1. The header for the blue query table is being copied onto sheet2. This isn't required.
    2. If I filter a column in the blue query table and run the macro, all of the data is being copied to sheet2 and not just the filtered visible data.

    The functionality of the code in my original post is fine, it's just extending the range when I update and refresh the query file which is the issue.

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extend copy range of a macro in a query file

    Well, if your code works with the filtered data then this may solve your problem:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    10-10-2012
    Location
    Warks
    MS-Off Ver
    Excel 2013
    Posts
    91

    Re: Extend copy range of a macro in a query file

    That's it! Thank you, really appreciate you taking a look at that.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extend copy range of a macro in a query file

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

    And, You're welcome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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