Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
ayl322
 
Posts: n/a
Default 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!


--
ayl322
------------------------------------------------------------------------
ayl322's Profile: http://www.excelforum.com/member.php...fo&userid=9846
View this thread: http://www.excelforum.com/showthread...hreadid=467641

  #2   Report Post  
Rowan
 
Posts: n/a
Default

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   Report Post  
ayl322
 
Posts: n/a
Default


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!


--
ayl322
------------------------------------------------------------------------
ayl322's Profile: http://www.excelforum.com/member.php...fo&userid=9846
View this thread: http://www.excelforum.com/showthread...hreadid=467641

  #4   Report Post  
Rowan
 
Posts: n/a
Default

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   Report Post  
ayl322
 
Posts: n/a
Default


Thanks Rowan!
Works perfectly! :)


--
ayl322
------------------------------------------------------------------------
ayl322's Profile: http://www.excelforum.com/member.php...fo&userid=9846
View this thread: http://www.excelforum.com/showthread...hreadid=467641

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting rows with alphanumeric starter cells axlmastr Excel Worksheet Functions 8 September 9th 05 03:28 PM
How to keep rows together when sorting columns? Amit Excel Worksheet Functions 1 March 28th 05 06:01 PM
Sorting rows AND columns 3D Excel Worksheet Functions 2 January 7th 05 02:15 AM
sorting detail rows - summary row in an outline ExcelSteve Excel Discussion (Misc queries) 1 December 5th 04 02:40 PM
Macro for sorting different rows ciscopena Excel Worksheet Functions 0 November 1st 04 11:04 PM


All times are GMT +1. The time now is 10:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"