Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort rows alphabetically by whats in colum A

Status
Not open for further replies.

n3tw0rkadm1n1strat0r

IS-IT--Management
Aug 29, 2006
119
US
Does anyone know how to sort rows alphabetically by whats in column A for excel?
 
And what have you tried so far ?
A common way is to use the Excel's macrorecorder to get the VBA code and then adapt it to VBS.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Ok well I recorded it, and here is the vba code:

Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/26/2007 by Spectacor-Complex
'

'
    Application.WindowState = xlMinimized
    Application.WindowState = xlNormal
    Application.WindowState = xlMinimized
    Application.WindowState = xlNormal
    Selection.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortNormal
End Sub

I wouldn't know how to modify this for vbscript...
 
Again, what is your actual VBS code and where in it are you stuck ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I thought this might work goin off of what you showed me before...but I'm getting errors with special cells.

Code:
objExcel.Range("A:AH").Select
objExcel.Selection.Specialcells(4).Key1' 4 = Range("A2")
objExcel.Selection.Specialcells(4).Order' 4 = xlAscending
objExcel.Selection.Specialcells(4).Header' 4 = xlGuess
objExcel.Selection.Specialcells(4).OrderCustom' 4 = 1
objExcel.Selection.Specialcells(4).MatchCase' 4 = False
objExcel.Selection.Specialcells(4).Orientation' 4 = xlTopToBottom
objExcel.Selection.Specialcells(4).DataOption1' 4 = xlSortNormal
 
Why not simply this ?
objExcel.Range("A:AH").Sort objExcel.Range("A2")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
objExcel.Range("A:AH").Sort objExcel.Range("A2"),,,,,,,0 ' 0=xlGuess

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 



Check HELP...
[tt]
expression.Sort(Key1, Order1, Key2, Type, Order2, Key3, Order3, Header, ...
[/tt]
7 commas.

Skip,

[glasses] [red][/red]
[tongue]
 
In your macro posted 26 Feb 07 10:37, put the cursor in the Sort word and press F1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top