« Excel: Matching Text Against a List of Words | Main | PPC: Click Fraud »

Excel Macro: Alpha Sort Across Columns

It's the easiest thing in the world to sort a column alphabetically. But what if you have a column with a bunch of words in each row, and you want to sort the words within each cell?

For instance:

A1 - Tom ate lunch
A2 - Alex brought animal cookies
A3 - Games were played

I want to sort each sentence. A1 should be "ate lunch Tom," see.

1. I approached it by splitting the cells into columns, first. (Data > Text to Colums > Space delimited)
2. Then I ran the following macro:

===============================
Sub AlphaRowSort()
'
' AlphaRowSort Macro
' By Tom Dalton
'
'
Do Until ActiveCell.Value = ""
ActiveCell.Range("A1:Z1").Select
Selection.Sort Key1:=ActiveCell, Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlLeftToRight, _
DataOption1:=xlSortNormal
ActiveCell.Offset(1, 0).Select
Loop
End Sub
=====================

3. Then I copied all the cells into notepad to clean it, copied that into Word, replaced all the tabs with spaces, and finally dumped it back into Excel.

If I were any good at writing macros, of course, I'd have put all the splitting and recombining into the macro as well. But I'm not -- I'm not a programmer! I just get things done. And this got done in time. So I'm a happy boy.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on July 11, 2006 4:32 PM.

The previous post in this blog was Excel: Matching Text Against a List of Words.

The next post in this blog is PPC: Click Fraud.

Many more can be found on the main index page or by looking through the archives.