+ Reply to Thread
Results 1 to 3 of 3

Need macro to sort rows

  1. #1
    Onfrek
    Guest

    Need macro to sort rows

    Hi, all!
    I need macro that sort selected row and then jump to next row and so on
    to the end of Sheet. I recorded this macro:

    Sub Makro1()
    Range("E2:H2").Select
    Selection.Sort Key1:=Range("E2"), Order1:=xlAscending,
    Header:=xlGuess, _
    OrderCustom:=5, MatchCase:=False, Orientation:=xlLeftToRight
    End Sub

    This one sorts only one row, how can i solve my problem?
    Thanks for any help


  2. #2
    Dave Peterson
    Guest

    Re: Need macro to sort rows

    I used column E to determine the last row to sort.

    Option Explicit
    Sub Makro1A()

    Dim LastRow As Long
    Dim FirstRow As Long
    Dim iRow As Long

    With ActiveSheet
    FirstRow = 2
    LastRow = .Cells(.Rows.Count, "E").End(xlUp).Row
    For iRow = FirstRow To LastRow
    With .Cells(iRow, "E").Resize(1, 4)
    .Sort key1:=.Columns(1), Order1:=xlAscending, Header:=xlNo, _
    OrderCustom:=5, MatchCase:=False, _
    Orientation:=xlLeftToRight
    End With
    Next iRow
    End With

    End Sub

    ..resize(1,4) says to take that range (whatever row, column E) and make it 1 row
    high by 4 columns wide (E:H).

    I changed the header to xlno. If you know whether you have headers, then it's
    usually best to specify what you know.

    Onfrek wrote:
    >
    > Hi, all!
    > I need macro that sort selected row and then jump to next row and so on
    > to the end of Sheet. I recorded this macro:
    >
    > Sub Makro1()
    > Range("E2:H2").Select
    > Selection.Sort Key1:=Range("E2"), Order1:=xlAscending,
    > Header:=xlGuess, _
    > OrderCustom:=5, MatchCase:=False, Orientation:=xlLeftToRight
    > End Sub
    >
    > This one sorts only one row, how can i solve my problem?
    > Thanks for any help


    --

    Dave Peterson

  3. #3
    Onfrek
    Guest

    Re: Need macro to sort rows

    Thanks Dave, it works!
    The funny thing - for about two weeks ago I had the same problem and
    found another solution(not so good as yours), but today I was not able
    to do this again.

    It was small macro that sorted one row and jumped then to next row and
    stopped. I had to run it again and again to the last row, with shortcut
    it was pretty quick. But your solution is much more better.
    Regards, Onfrek


+ 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