+ Reply to Thread
Results 1 to 3 of 3

Range selection in macros for sorting data

  1. #1
    Registered User
    Join Date
    01-17-2010
    Location
    London, England
    MS-Off Ver
    Excel 2003, 2007, & 2010 Beta
    Posts
    86

    Range selection in macros for sorting data

    Hi, my first posting - I've a simple but incomvenient problem, so here goes: I have data on a spreadsheet which, each day, will have a few extra rows in it than before. I'm not good at composing VBA programs so I just record macros. I want a macro to select the data and sort all of it, according to a particular sort sequence. The steps I take in recording the macro are: Ctrl-Home (so it jumps to, say, cell A4); select the data (I do Ctrl-*); sort the data (I carry out the sort commands); select A4 once again. Stop recording. Thing is, when I do Ctrl-* Excel will nicely pick up all the data in continuous rows & columns, no matter how far down it needs to go (or across). The macro 'reading', on the other hand, will just select, say A4:G127, and, next time it is run, even though there is data in row 128, it will stop at row 127. I need the VBA way of saying something like down(x1).select - I can't remember quite how it is phrased. I tried relative references (in Excel 2007), but that does not seem to alter how it works. What's the line of programming, please, that I want, to select as far down or across as the selection needs to go (as far as there is data)? Thanks for any help.

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: problem with range selection in macros for sorting data

    lotusman
    some thing like
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Range selection in macros for sorting data

    My thoughts:
    Please Login or Register  to view this content.
    By the way, you don't have select ranges of data to sort them. The macro recorder shows you "selecting" because it is a recorder, it records your human activities, not the simplest way to do it.

    When you record macros, you can typically combine several lines of recorded code to remove the selections and merge the commands into one direct activity.
    Please Login or Register  to view this content.
    [/B]
    Last edited by JBeaucaire; 01-17-2010 at 09:21 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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