Consulting

Results 1 to 2 of 2

Thread: Sorting CurrentRegion?

  1. #1
    VBAX Regular
    Joined
    Jun 2005
    Posts
    95
    Location

    Sorting CurrentRegion?

    Hello,

    I am trying to sort based on a CurrentRegion selection. I keep getting an error. Can anyone help?

    [vba]
    activeCell.CurrentRegion.Select
    Selection.Sort.SortFields.Add Key1:=Range("T1"), Order:=xlDescending, _
    Key2:=Range("D1"), Order:=xlAscending, Header:=xlGuess, MatchCase:=False, _
    Orientation:=xlTopToBottom, DataOption:=xlSortNormal
    [/vba]

    Thank you in advance!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Where did you get this code? It seems to be a mix of 2007 and pre-2007 methods.

    For 2007

    [vba]

    With ActiveSheet.Sort
    .SortFields.Add Key:=Range("T1"), Order:=xlDescending
    .SortFields.Add Key:=Range("D1"), Order:=xlAscending
    .SetRange ActiveCell.CurrentRegion
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .Apply
    End With
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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