View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] curt.dye@gmail.com is offline
external usenet poster
 
Posts: 1
Default Alphabetize Columns

I'm looking to put columns in alphabetical order based upon their
content in a given row. This works, but it seems to be rather
inefficient. Is there a better way of doing this?

Sub AlphaColumns()
rw = 1
cStart = 1
cEnd = 10

For i = cStart To cEnd
For j = i To cEnd
If UCase(Cells(rw, i).Value) UCase(Cells(rw, j).Value) Then
Cells(1, i).EntireColumn.Select
Selection.Cut
Cells(1, j + 1).EntireColumn.Select
Selection.Insert Shift:=xlToRight
i = Application.WorksheetFunction.Max(cStart, i - 1)
End If
Next j
Next i

End Sub