|
-
May 11th, 2005, 06:15 AM
#1
Thread Starter
Fanatic Member
How to use the 'sort' function in a worksheet?
hello,
I'm using an excel worksheet in my app and I wondered how do I use the
'sort' function to sort my first column alphabeticlly...
thanks
-
May 11th, 2005, 06:21 AM
#2
Frenzied Member
Re: How to use the 'sort' function in a worksheet?
Code:
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
or if you want descending sort ...
Code:
Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
-
May 11th, 2005, 12:42 PM
#3
Thread Starter
Fanatic Member
Re: How to use the 'sort' function in a worksheet?
what does the Key1:=Range("A1") stands for?
-
May 11th, 2005, 01:01 PM
#4
Re: How to use the 'sort' function in a worksheet?
Thats the column your sorting.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
May 12th, 2005, 05:44 AM
#5
Thread Starter
Fanatic Member
Re: How to use the 'sort' function in a worksheet?
what do I need to put in the selection variable?
what does it need to stand for?
-
May 12th, 2005, 05:48 AM
#6
Frenzied Member
Re: How to use the 'sort' function in a worksheet?
 Originally Posted by dekelc
what do I need to put in the selection variable?
what does it need to stand for?
The above can be run from within Excel (using VBA)
If you are manipulating Excel from VB, then you need to first create an Excel object. Assuming you have the Excel library included in your project then then above code just needs to be prefixed with your Excel object name.
Assuming your object naem is objExcel, then the code would read as :
Code:
objExcel.Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
I'm presuming thats what you meant !
-
May 12th, 2005, 06:07 AM
#7
Thread Starter
Fanatic Member
Re: How to use the 'sort' function in a worksheet?
yes, but I need to select something first.
what do I need to select? the column? the worksheet?
and how do I select it?
-
May 12th, 2005, 06:11 AM
#8
Frenzied Member
Re: How to use the 'sort' function in a worksheet?
If its column A you need to sort on, then just use the above code.
You don't need to select anything first. The Range specified in the "key" part of the statement takes care of that.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|