+ Reply to Thread
Results 1 to 5 of 5

sorting a constantly changing set of rows in VBA

  1. #1
    Registered User
    Join Date
    05-24-2004
    Posts
    16

    sorting a constantly changing set of rows in VBA

    I have a list of customer names in cells A87:A??
    I need to sort this list, but the list might get longer when names are added.
    I have a VBA code that adds the rows, and within that same code I need to sort this list alphabetically.
    Is there a way to write this code?
    I need it to only sort the rows that has the data in A87 to A[end of the list].

    something like:
    y = range("A87").end(xldown).row
    range("A87:A" & "y").sort xlascending

    of course the above code doesn't work but it kinda shows what i want it to do.

    Any help would be greatly appreciated!

  2. #2
    Rowan
    Guest

    Re: sorting a constantly changing set of rows in VBA

    Try:

    Dim y As Long
    y = Cells(Rows.Count, 1).End(xlUp).Row
    Range("A87:A" & y).Sort Key1:=Range("A87"), Order1:=xlAscending

    Regards
    Rowan

    ayl322 wrote:
    > I have a list of customer names in cells A87:A??
    > I need to sort this list, but the list might get longer when names are
    > added.
    > I have a VBA code that adds the rows, and within that same code I need
    > to sort this list alphabetically.
    > Is there a way to write this code?
    > I need it to only sort the rows that has the data in A87 to A[end of
    > the list].
    >
    > something like:
    > y = range("A87").end(xldown).row
    > range("A87:A" & "y").sort xlascending
    >
    > of course the above code doesn't work but it kinda shows what i want it
    > to do.
    >
    > Any help would be greatly appreciated!
    >
    >


  3. #3
    Registered User
    Join Date
    05-24-2004
    Posts
    16
    thanks Rowan, but it doesn't quite work...
    maybe i should explain more.
    i have 2 groups of names, one right underneath the other.
    so if a name is added to the first group, all the rows shift down.
    i need to be able to sort just the names in the first group alphabetically.
    the 2 groups are separated by a blank line, which is why i thought RANGE("A87").END(XLDOWN) might be useful somehow.

    any help would be appreciated!

  4. #4
    Rowan
    Guest

    Re: sorting a constantly changing set of rows in VBA

    Try:

    Dim y As Long
    y = Cells(87, 1).End(xlDown).Row
    Range("A87:A" & y).Sort Key1:=Range("A87"), Order1:=xlAscending

    Regards
    Rowan

    ayl322 wrote:
    > thanks Rowan, but it doesn't quite work...
    > maybe i should explain more.
    > i have 2 groups of names, one right underneath the other.
    > so if a name is added to the first group, all the rows shift down.
    > i need to be able to sort just the names in the first group
    > alphabetically.
    > the 2 groups are separated by a blank line, which is why i thought
    > RANGE("A87").END(XLDOWN) might be useful somehow.
    >
    > any help would be appreciated!
    >
    >


  5. #5
    Registered User
    Join Date
    05-24-2004
    Posts
    16
    Thanks Rowan!
    Works perfectly!

+ 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