Sort

The Sort method is used to sort the cells in the range from top to bottom.

Syntax

object.Sort( Col1, Order1, Col2, Order2, Col3, Order3, Header, MatchCase )

Parameter

Type

Required/

Optional

Default

Description

Col1

Long

Optional

-1

This specifies the primary column on which the rows are sorted or the 'Sort First By' Column

Order1

wksSort

Optional

wksSortAscending

optional, default=wksSortAscending

Col2

Long

Optional

-1

When two or more rows have identical entries in the col1, this provides the' Sort Next By' column, which further organizes the data set.

Duplicates in the Sort First By Column are then sorted according to the rank in the Sort Next By column.

Order2

wksSort

Optional

wksSortAscending

optional, default=wksSortAscending

Col3

Long

Optional

-1

This provides the ' Sort Last By' column when the col2 contains duplicates.

Order3

wksSort

Optional

wksSortAscending

optional, default=wksSortAscending

Header

Boolean

Optional

False

This value is set to 'True' to exclude the label row from the sort process.

Setting this value to 'True' means labels in first row, do not sort first row.

MatchCase

Boolean

Optional

False

This specifies the sort to be case sensitive.

Example

This example demonstrates how to sort the second, third then first columns of a range all in descending order.

WksRange.Sort(Col1:=2, Order1:=wksSortDescending, Col2:=3, _

Order2:=wksSortDescending, Col3:=1, _

Order3:=wksSortDescending, Header:=True, MatchCase:=False)

Used by: WksRange object