+ Reply to Thread
Results 1 to 5 of 5

Run-time error when trying to sort a range

  1. #1
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Run-time error when trying to sort a range

    Hello all.

    I am trying to sort a range within a range and keep getting a runtime error that I can't seem to fix.

    Here is my code:

    Please Login or Register  to view this content.
    I have a range that has a blank row at the top and bottom. I need to keep these blank rows so sorting the whole range won't work.

    The "Set rng" and "rng.Select" code work properly.

    Now I want to sort the newly selected subrange by the first column (which holds dates) in ascending order (oldest to newest).

    With the code I have, I get a '1004' run-time error which states "Method 'Range' of object '_Global' failed.

    This is a new one for me.

    Any help is appreciated.

    Thank you,

    Brian

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Run-time error when trying to sort a range

    Maybe ...

    Please Login or Register  to view this content.
    Last edited by shg; 08-17-2012 at 06:09 PM. Reason: added reference operator
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Run-time error when trying to sort a range

    This code gives the same '1004' error but now says "Application-defined or object-defined error" and highlights the following line of code:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-15-2012
    Location
    Las Vegas
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Run-time error when trying to sort a range

    Fixed it.

    Please Login or Register  to view this content.
    Using "Range(rng(1, 1))" for the sort key was the problem.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Run-time error when trying to sort a range

    Corrected in prior post (the big red dot).

+ 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