Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Nov 2002
    Location
    London, Gtr London, England
    Posts
    496
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Sort not quite working...

    Dear loungers,

    I am doing something stupid and am too tired to see what is probably obvious! This was originally a recorded macro (2010) which I then adjusted. I have sliced out the relevant bits from arather larger module. The error is to do with .SetRange

    Code:
    Dim sSortArea As Sort                        ' the sort itself
    Dim wsThisWorkSheet As Worksheet        ' the worksheet
    Set wsThisWorkSheet = ActiveSheet
    Set sSortArea = wsThisWorkSheet.Sort
    
    'Sort the data, based on two columns the ref number and the date
        sSortArea.SortFields.Clear
        sSortArea.SortFields.Add Key:=Range("WorkRef"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
        sSortArea.SortFields.Add Key:=Range("MsgDate"), SortOn:=xlSortOnValues, Order:=xlAscending
        
        With sSortArea
            .SetRange Range("rActiveRange")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Can anyone see anything wrong?

    Thank you................. liz
    Last edited by lizat; 2011-10-17 at 17:59.

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    Is rActiveRange a Range object variable, or the name of a range? If the former, then it should be:
    Code:
    .SetRange rActiveRange
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •