Sort by cell value before extracting to text file.

  • Hi,



    I am trying to make a Generic Script Maker, and would like to sort the scripts in ascending order by the Sequence column. ( So basically numerical values are to be inserted in Sequence. I am encountering "Select Method of class Range Failed." when using the


    Code
    Range("A1:D1").Select    Selection.Sort Key1:=Range("E2"), Order1:=xlAscending, Header:=xlYes, _
         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
         DataOption1:=xlSortNormal


    Attached also is the Workbook. forum.ozgrid.com/index.php?attachment/70016/


    Any help is appreciated.


    Regards,
    Mot

  • Re: Sort by cell value before extracting to text file.


    There isn't any data or sort code in your file. I think the problem is that you are sorting by a cell which is not inside the sort range (E>D).

  • Re: Sort by cell value before extracting to text file.


    Hi Stephen,


    I have commented it so the program would run, anyway attached is the sample workbook.


    I have updated the sort range into

    Code
    Range("A2:F2").Select
        Selection.Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _
         OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
         DataOption1:=xlSortNormal


    still encountering the problem.


    Mot

  • Re: Sort by cell value before extracting to text file.


    Workbooks are good, but not much use if there's nothing in them!


    So in your latest snippet you are only sorting A2:F2, i.e. one row of data so you need something like

    Code
    Range("A2:F20").Sort Key1:=Range("F2"), Order1:=xlAscending, Header:=xlYes, _ 
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ 
    DataOption1:=xlSortNormal
  • Re: Sort by cell value before extracting to text file.


    Forgot to add that the user will input the value for Sequence Column (E). Will try the suggested code. Thanks!

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!