Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Alphabetize Columns

Sub AlphaColumns()

rw = 1
cStart = 1
cEnd = 10

Set SortRange = Range(Cells(rw, cStart), Cells(rw, cEnd))

SortRange.Sort _
Key1:=Cells(rw, cStart), _
Order1:=xlAscending, _
header:=xlNo, _
Orientation:=xlLeftToRight
End Sub

" wrote:

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Alphabetize Columns

Cells.Sort Key1:=Rows(rw), Order1:=xlAscending, Orientation:=xlLeftToRight
--
Jim Cone
Portland, Oregon USA






wrote in message
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


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
How to alphabetize 8 columns as one? kwiley Excel Discussion (Misc queries) 1 December 8th 09 04:19 PM
Alphabetize in multiple columns Brian Pope Excel Discussion (Misc queries) 2 November 11th 09 01:43 PM
alphabetize EC Excel Discussion (Misc queries) 4 December 13th 06 12:36 AM
Can I alphabetize the info in my columns? MrsB New Users to Excel 2 September 22nd 06 09:49 PM
Alphabetize? lisaz530 Excel Discussion (Misc queries) 1 August 16th 06 01:12 AM


All times are GMT +1. The time now is 09:47 PM.

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"