Results 1 to 3 of 3

Need help fixing macros due to Run-Time error 1004 Sort Reference is Not Valid

Threaded View

  1. #1
    Registered User
    Join Date
    05-11-2013
    Location
    Portland
    MS-Off Ver
    Excel 2007
    Posts
    9

    Need help fixing macros due to Run-Time error 1004 Sort Reference is Not Valid

    Hello,

    I am trying to write a macros to select a range of cells and then sort alphabetically in ascending order using information found in another range. For my example below the larger range is called "Team Ambrosio" and within that range is another range called "CSR_Ambrosio". I am trying to write a macros that will sort the larger range (Team_Ambrosio) in ascending order based on the text values of the smaller range (SCR_Ambrosio).

    I tried recording a macros and then substituting the cell ranges with the names of the cell ranges. I then replaced the Worksheet name using "ActiveSheet" because I need the macros to run on whatever sheet is active at the time. This may be where my problem is, I'm not sure. But I do not want to use the "Worksheet Name" because the name will be changing every time I create a new worksheet.

    I receive the following error: 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. The debugger takes me to the ".Apply" line below. Any help would be appreciated on how to get this to function correctly. Thanks!

        Range("Team_Ambrosio").Select
        ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
        ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("CSR_Ambrosio"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.ActiveSheet.Sort
            .SetRange Range("Team_Ambrosio")
            .Header = xlGuess
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Last edited by Leith Ross; 06-15-2013 at 08:19 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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