PDA

View Full Version : Sleeper: How to create a sort instruction



red bitroot
05-20-2005, 04:43 AM
I created a sort instruction by using a macro in Excel.
It is as follows :


Selection.Sort Key1:=Range("A217"), Order1:=xlAscending, Key2:=Range( _
"B217"), Order2:=xlAscending, Key3:=Range("C217"), Order3:=xlDescending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:= _
xlTopToBottom, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal, _
DataOption3:=xlSortNormal

I would create this instruction programmatically with VBA in order to use following instruction

Selection.Sort SortProjectParameters

where SortProjectParameters is a string that I've fullfilled according to the sort parameters I want to use.

When the sort is launch, I receive the message :

Execution error 13
Incompatibilit? de type (sorry, but I'm using the french version of Excel).

Can somebody help me ?

Thanks in advance.

Red bitroot :hi:

mdmackillop
05-20-2005, 02:39 PM
Hi,

Try the following. The difficulties seem to be with the Type and SortMethod parameters. Note the extra comma in Selection.Sort after Key 2; SortMethod is not used.


Sub Sortit()
DoSort [A217], xlAscending, [B217], xlAscending, [C217], xlDescending, _
xlGuess, 1, False, xlTopToBottom, xlSortNormal, xlSortNormal, xlSortNormal
End Sub

Sub DoSort(Key1, Order1, Key2, Order2, Key3, Order3, Header, OrderCustom, _
MatchCase, Orientation, DataOption1, DataOption2, DataOption3)
[A217].CurrentRegion.Select
Selection.Sort Key1, Order1, Key2, , Order2, Key3, Order3, Header, OrderCustom, _
MatchCase, Orientation, DataOption1, DataOption2, DataOption3
[A217].Select
End Sub