Consulting

Results 1 to 3 of 3

Thread: Column Sorting

  1. #1

    Column Sorting

    I recorded a macro so that I could hopefully learn how to code it, but I'm having problems.

    ActiveCell.Cells.Select
    Selection.Sort Key1:=ActiveCell.Offset(0, 2).Range("A2"), Order1:= _
    xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers

    What am I doing wrong below?

    ActiveCell.CurrentRegion.Select
    Range("CurrentRegion").Sort Key1:=Range("C1")

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    CurrentRegion is a VBA range, you are trying to use it as an Excel defined name.

    Try

    [vba]

    ActiveCell.CurrentRegion.Select
    Selection.Sort Key1:=Range("C1")
    [/vba]

    or better still

    [vba]

    ActiveCell.CurrentRegion.Sort Key1:=Range("C1")
    [/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

  3. #3
    Thank you!

Posting Permissions

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