+ Reply to Thread
Results 1 to 4 of 4

The Sort Reference Is Not Valid

  1. #1
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    The Sort Reference Is Not Valid

    I have a tab with four different sets of similar data. Each pasted from a pivot table with a different item in filter selected. I need to sort each column desc, which is why i can't leave it in the pivot. I have four sets of similar code, only the starting point of the data sets changes. When running the macro, the first data set sorts perfectly. But when i get to the apply step in the second set of code, it tells me "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."

    Below are the first two sets of code
    Please Login or Register  to view this content.
    I can’t for the life of me figure out why I’m getting that error. I threw in those test-test4 variables to help me, but as far as i can tell the outputs are what they should be. IE test matches test3 and test2 matches test4. The ending rows and starting columns are different, but looking at the data they match.

    Capture.PNG

    Any assistance would be appreciated.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: The Sort Reference Is Not Valid

    No offense, I hope, but I found the code to be unnecessarily complex and confusing (especially with all the unneeded ConvertToLetter function calls, to the point where it was easier to just rewrite it rather than decipher it. Give this a try. It will work for any number of data sets (as long as they all start on the same row) and any number of columns within each set:

    Please Login or Register  to view this content.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  3. #3
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    Re: The Sort Reference Is Not Valid

    Oh, no offense taken. There's always a better way. I appreciate the rework. I'll take a look and see how it goes.

    Thanks again.

  4. #4
    Forum Contributor
    Join Date
    01-09-2006
    Posts
    109

    Re: The Sort Reference Is Not Valid

    Wow that's so much more elegant than what I was trying. Worked like a charm. If you're ever in Birmingham, AL, I owe you a beer!!! Thanks so much.

+ 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. The Sort reference is not valid - run time error
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-23-2014, 09:14 AM
  2. Need help fixing macros due to Run-Time error 1004 Sort Reference is Not Valid
    By travisg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2013, 12:13 AM
  3. Sort Reference is Not Valid
    By nickv02 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-07-2012, 04:43 PM
  4. 'reference is not valid'
    By Tim in forum Excel General
    Replies: 12
    Last Post: 06-21-2006, 02:36 PM
  5. [SOLVED] Reference is not valid
    By Steved in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 01-30-2006, 07:00 PM

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