+ Reply to Thread
Results 1 to 7 of 7

How can I select data to the end of a range in a macro?

  1. #1
    Registered User
    Join Date
    05-06-2014
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    How can I select data to the end of a range in a macro?

    I want my macro to always select all the data in a range. The problem is if I specify a range it will always select that exact range, not the data itself. I've tried converting it to a table but the same problem occurs, it will always do the same range of cells instead of the actual data.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How can I select data to the end of a range in a macro?

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    05-06-2014
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How can I select data to the end of a range in a macro?

    Hi,
    Here is a good example, it looks like when it comes to the selection, maybe it is selecting to the end of the data, but when it does the command to format the selection as a table it explicitly does the range in the example file I used to setup the macro. I think what needs to be edited is the Range() parameter in the .Add section that creates Table1:

    Please Login or Register  to view this content.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How can I select data to the end of a range in a macro?

    No, that's not a good example, it's a different example.

    If you have a Structured Table, Table1, and you want to select the data, you can use:

    Please Login or Register  to view this content.
    But, in practical terms, you should avoid selecting anything. In the majority of cases, it isn't necessary.


    Regards, TMS

  5. #5
    Registered User
    Join Date
    05-06-2014
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    7

    Re: How can I select data to the end of a range in a macro?

    No, I'm not trying to select the table, here I am creating the table. I select to the end of the data and then click format as table, but the macro interprets that as converting a literal range. The next time I run this macro on a file it will convert A1 to F120 to a table instead of all the data. I think I need to replace Range("$A$1:$F$120") with something that would always capture the entire range.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How can I select data to the end of a range in a macro?

    Please Login or Register  to view this content.

    BUT, you're not going to be able to run the macro more than once because the Table will already exist and you won't be able to overlap a table.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,528

    Re: How can I select data to the end of a range in a macro?

    Avoiding the problem ...

    Please Login or Register  to view this content.

    Regards, TMS

+ 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. [SOLVED] Macro to select a date range within data with dates
    By akynyemi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2013, 11:58 AM
  2. [SOLVED] macro to select data range in rows correctly..
    By arifmasum in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2012, 07:33 AM
  3. Macro to select data within a date range.
    By dannymcg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-12-2012, 05:44 AM
  4. Macro to select cells at end of range of data
    By johnlynches in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2012, 02:32 PM
  5. [SOLVED] Macro to select only cells within the range that contain data
    By wojo in forum Excel General
    Replies: 14
    Last Post: 07-22-2005, 02:05 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