' ============================================================================
'#####Сортировка столбца на листе
'*****столбец должен быть весь заполнен
'Sub test_FnSortColumn()
' 'Cells(4, 7).Sort Key1:=Cells(3, 7), Order1:=xlAscending, Header:=xlYes
' Сортировка = FnSortColumn(ThisWorkbook.Sheets("main"), 7, 3)
'End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FnSortColumn(ByVal oSh As Worksheet, _
ByVal iNbClnSort As Long, _
Optional iNbRowSort As Long, _
Optional ByVal blnTypeSort As Boolean = True) As Boolean
On Error Resume Next
Err.Clear
Select Case blnTypeSort
Case True: 'Order1:=xlAscending
oSh.Cells(iNbRowSort + 1, iNbClnSort).Sort Key1:= oSh.Cells(iNbRowSort, iNbClnSort), Order1:=xlAscending, Header:=xlYes
Case False: 'Order1:=xlDescending
oSh.Cells(iNbRowSort + 1, iNbClnSort).Sort Key1:= oSh.Cells(iNbRowSort, iNbClnSort), Order1:=xlDescending, Header:=xlYes
End Select
Debug.Print " - " & Err.Description
If Len(Err.Description) = 0 Then FnSortColumn = True
End Function
' ============================================================================
'Сортировка
' NbColDATE = ShTemp.Rows(1).Find(What:="XXXXXXX", LookAt:=xlWhole).Column
' ShTemp.Cells(2, NbColDATE).Sort Key1:=ShTemp.Cells(1, NbColDATE), Order1:= _
' xlDescending, DataOption:=xlSortNormal
' lngClnSort = 1: .Cells(2, lngClnSort).Sort Key1:=.Cells(1, lngClnSort), Order1:=xlDescending ', DataOption:=xlSortNormal
' lngClnSort = 2: .Cells(2, lngClnSort).Sort Key1:=.Cells(1, lngClnSort), Order1:=xlAscending, Header:=xlYes
' lngClnSort = 1: .Cells(2, lngClnSort).Sort Key1:=.Cells(1, lngClnSort), Order1:=xlAscending, Header:=xlYes