+ Reply to Thread
Results 1 to 4 of 4

Sort Reference is Invalid

  1. #1
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Sort Reference is Invalid

    I'm trying to set up a Subroutine that deletes blank rows in a report, then sorts the rows by the time. I'm not sure what is going on with it, but below is the full routine:

    Please Login or Register  to view this content.
    The delete works fine, but the sort errors out: "Run-time error '1004': The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank."

    Does it matter that EndCell is empty? Every cell in timecolumn is populated with a time, correctly formatted.

    I don't have any blank rows, so I can't use CurrentRegion to select the sort area. But if there's another way to write that line, I'd appreciate any info you can give.
    Last edited by dhunton; 01-05-2017 at 09:19 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Sort Reference is Invalid

    I would really like to have your full Excel file.

    Meantime, if EndCell is in a row that gets deleted you'll have an error. It would refer to a range that doesn't exist anymore. If you set a Range variable to A10, for example, then delete row 10, the reference becomes invalid; it does not refer whatever has now become the new A10.

    I suggest that you set EndCell immediately before the sort.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    05-02-2016
    Location
    USA
    MS-Off Ver
    2013
    Posts
    35

    Re: Sort Reference is Invalid

    Quote Originally Posted by 6StringJazzer View Post
    I would really like to have your full Excel file.
    It's over 2,000 lines of code, not including comments and spacing lines...

    Meantime, if EndCell is in a row that gets deleted you'll have an error. It would refer to a range that doesn't exist anymore. If you set a Range variable to A10, for example, then delete row 10, the reference becomes invalid; it does not refer whatever has now become the new A10.

    I suggest that you set EndCell immediately before the sort.
    And that's all it needed. LOL Thank you for putting another set of eyes on it!

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,696

    Re: Sort Reference is Invalid

    Glad it worked!

+ 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] Invalid Reference
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2016, 04:06 AM
  2. invalid or unqualified reference
    By cmccabe in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2015, 02:01 PM
  3. Invalid reference error in VBA
    By ConneXionLost in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-26-2010, 06:15 PM
  4. [SOLVED] Invalid Sort Reference Error
    By hchurch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-13-2010, 01:52 PM
  5. Replies: 3
    Last Post: 05-13-2009, 11:51 PM
  6. How do I fix an Invalid Reference?
    By Nic in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-01-2006, 11:50 AM
  7. [SOLVED] Another invalid or unqualified reference
    By davegb in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 08-31-2005, 02:05 PM

Tags for this Thread

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