Results 1 to 2 of 2

Sort Macro not working.

Threaded View

  1. #1
    Registered User
    Join Date
    05-19-2009
    Location
    California
    MS-Off Ver
    Excel 2013-16
    Posts
    55

    Sort Macro not working.

    Sub Test()
    
    Dim SortLastRow As Long
    Dim SortLastColumn As Long
    
    Range("A1").Select
     On Error Resume Next
        SortLastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).Row
        SortLastColumn = Cells.Find("*", [A1], , , xlByColumns, xlPrevious).Column
        SortLastCell = Cells(SortLastRow, SortLastColumn).Address
    SortRange = "A1:" & SortLastCell
    
    Range(SortRange).Select
    intSortRC = Selection.Rows.Count
    
    Range("A1").Select
    Cells.Find("Network #", ActiveCell, xlValues, xlWhole, xlByColumns, xlNext, False, False).Select
    Selection.Resize(intSortRC, 1).Select
    Selection.Name = "SortNetworkRange"
    
    Range("A1").Select
    Cells.Find("Position #", ActiveCell, xlValues, xlWhole, xlByColumns, xlNext, False, False).Select
    Selection.Resize(intSortRC, 1).Select
    Selection.Name = "SortPositionRange"
    
    Range("A1").Select
    Cells.Find("Room", ActiveCell, xlValues, xlWhole, xlByColumns, xlNext, False, False).Select
    Selection.Resize(intSortRC, 1).Select
    Selection.Name = "SortRoomRange"
        
        Range(SortRange).Activate
        
        ActiveWorkbook.Worksheets("Full").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Full").Sort.SortFields.Add Key:=Range(SortNetworkRange), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Full").Sort.SortFields.Add Key:=Range(SortPositionRange), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Full").Sort.SortFields.Add Key:=Range(SortRoomRange), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        
        With ActiveWorkbook.Worksheets("Full").Sort
            .SetRange Range(SortRange)
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        
    Range("A1").Select
    
    End Sub
    Anyone see what i have wrong in this code? I crafted it off of the record macro stuff so i might have it... wrong.

    any help would be great.

    Thanks
    Last edited by justforthis1; 07-24-2009 at 08:46 PM.

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