View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert[_2_] RB Smissaert[_2_] is offline
external usenet poster
 
Posts: 37
Default Sort a range of strings using VBA code?

There are lots of sorting routines that can sort an array
and it is easy to move values from a range to an array.
As you are working with worksheet ranges maybe you should
explain why you don't want to use the built-in Excel range sort.

RBS



"Robert Crandal" wrote in message
...
I would like to store a list of names in my spreadsheet. I will probably
use the range of A1 to A? to save my name list. Here's a small
example:

A1 = "Anderson, Tom"
A2 = "Baker, Richard"
A3 = "Foley, Bob"
A4 = "Peterson, Zack"

I will be adding new names to this list every day, so it is NOT
a fixed size list. Suppose tomorrow I need to add
"Carlson, Amanda" to the above list. The ideal sorted list will
be:

A1 = "Anderson, Tom"
A2 = "Baker, Richard"
A3 = "Carlson, Amanda"
A4 = "Foley, Bob"
A5 = "Peterson, Zack"

Does anyone know how to write a VBA "insert and sort" function that
achieves the above task? I am not interested in Excel's built-in sort
features....I would like to accomplish this with VBA code that sorts
or re-arranges a range of strings in cells. It seems to be a matter of
finding where the new name fits in the last, and then pushing all the
other names down by one cell.

The function/sub template might look approximately like this:

Public Sub InsertAndSort (NameBegin as Range, NameFinal as Range,
NameToAdd as String)
'
' Sort code
'
End Sub

I would really appreciate any ideas on how to achieve this.

Thank you!