Sort a range of strings using VBA code?
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!
|