+ Reply to Thread
Results 1 to 3 of 3

Data won't sort

  1. #1
    Paul Hammond
    Guest

    Data won't sort

    I've got a macro that opens a text file, formats it, adds headers, and the
    sorts the data. Everything works EXCEPT for the sorting. I get this error.

    "The sort reference is not valid. Make sure it is within the data you want
    to sort, and the first Sort By box isn't the same or blank."

    Here is where it hangs up. This was more or less recorded and used as is.


    Worksheets(MyWorkSheet).Range("B2").CurrentRegion.Select

    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    Key2:=Range("D2") _
    , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    DataOption2 _
    :=xlSortNormal

    TIA,

    Paul Hammond
    Richmond, Virginia

    --
    Can't we all just get along?

  2. #2
    Tom Ogilvy
    Guest

    Re: Data won't sort

    Why do you say B2 current region select and then try to use column A as a
    key?

    If column A is empty, then you will get this error.

    If you are running this code from a commandbutton, then Range("A1") refers
    to the sheet containing the code, not the sheet you are trying to sort. If
    that is the case then (and range("A1") is not empty)

    With Worksheets(MyWorkSheet).Range("B2")
    .CurrentRegion.Sort Key1:=.Range("A2"), Order1:=xlAscending, _
    Key2:=.Range("D2"), Order2:=xlAscending, _
    Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
    DataOption2:=xlSortNorma
    End With

    l



    --
    Regards,
    Tom Ogilvy


    "Paul Hammond" <[email protected]> wrote in message
    news:[email protected]...
    > I've got a macro that opens a text file, formats it, adds headers, and the
    > sorts the data. Everything works EXCEPT for the sorting. I get this

    error.
    >
    > "The sort reference is not valid. Make sure it is within the data you

    want
    > to sort, and the first Sort By box isn't the same or blank."
    >
    > Here is where it hangs up. This was more or less recorded and used as is.
    >
    >
    > Worksheets(MyWorkSheet).Range("B2").CurrentRegion.Select
    >
    > Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    > Key2:=Range("D2") _
    > , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,

    MatchCase:= _
    > False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    > DataOption2 _
    > :=xlSortNormal
    >
    > TIA,
    >
    > Paul Hammond
    > Richmond, Virginia
    >
    > --
    > Can't we all just get along?




  3. #3
    Paul Hammond
    Guest

    Re: Data won't sort

    Actually I had something exactly like that, for some reason it did not work.
    Your's did, must have been a comma somewhere.

    Thanks,

    Paul

    "Tom Ogilvy" wrote:

    > Why do you say B2 current region select and then try to use column A as a
    > key?
    >
    > If column A is empty, then you will get this error.
    >
    > If you are running this code from a commandbutton, then Range("A1") refers
    > to the sheet containing the code, not the sheet you are trying to sort. If
    > that is the case then (and range("A1") is not empty)
    >
    > With Worksheets(MyWorkSheet).Range("B2")
    > .CurrentRegion.Sort Key1:=.Range("A2"), Order1:=xlAscending, _
    > Key2:=.Range("D2"), Order2:=xlAscending, _
    > Header:=xlGuess, OrderCustom:=1, MatchCase:= _
    > False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
    > DataOption2:=xlSortNorma
    > End With
    >
    > l
    >
    >
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Paul Hammond" <[email protected]> wrote in message
    > news:[email protected]...
    > > I've got a macro that opens a text file, formats it, adds headers, and the
    > > sorts the data. Everything works EXCEPT for the sorting. I get this

    > error.
    > >
    > > "The sort reference is not valid. Make sure it is within the data you

    > want
    > > to sort, and the first Sort By box isn't the same or blank."
    > >
    > > Here is where it hangs up. This was more or less recorded and used as is.
    > >
    > >
    > > Worksheets(MyWorkSheet).Range("B2").CurrentRegion.Select
    > >
    > > Selection.Sort Key1:=Range("A2"), Order1:=xlAscending,
    > > Key2:=Range("D2") _
    > > , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1,

    > MatchCase:= _
    > > False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    > > DataOption2 _
    > > :=xlSortNormal
    > >
    > > TIA,
    > >
    > > Paul Hammond
    > > Richmond, Virginia
    > >
    > > --
    > > Can't we all just get along?

    >
    >
    >


+ Reply to Thread

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