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
:wave:
Printable View
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
:wave:
or if you want descending sort ...Code:Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Code:Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
what does the Key1:=Range("A1") stands for?
Thats the column your sorting.
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)Quote:
Originally Posted by dekelc
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 :
I'm presuming thats what you meant !Code:objExcel.Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
yes, but I need to select something first.
what do I need to select? the column? the worksheet?
and how do I select it?
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.