If I sort the column manually, accept text as number, no problem. But the code below refuses to sort the column. What am I missing???
I changed the sort range from a named range to bypass the header in my efforts to get this to run . . .
TIA!!!
Ron
NB: Had troubles with filters, so left in both possibilities.
I changed the sort range from a named range to bypass the header in my efforts to get this to run . . .
TIA!!!
Ron
NB: Had troubles with filters, so left in both possibilities.
Code:
Sub m_AD_Sort_ADATE()
'
Application.Volatile True
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.DisplayStatusBar = True
'
Sheets("AD").Select
ActiveWindow.DisplayGridlines = True
ActiveWindow.FreezePanes = False
'
Dim LastCol As Integer
Dim LastRow As Long
Dim Thiswb As Workbook
Dim Thiswksht As Worksheet
Set thisws = ActiveSheet
Set Thiswb = ActiveWorkbook
'
With Thiswksht
LastRow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
End With
'
If ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
'
If ActiveSheet.FilterMode = True Then
ActiveSheet.FilterMode = False
End If
'
ActiveWindow.FreezePanes = False
'
thisws.Sort.SortFields.Clear
'
Range("c_AD_ADATE").Select
'
With Selection
.HorizontalAlignment = xlRight
.VerticalAlignment = xlCenter
.NumberFormat = "dd/mm/yyyy"
End With
'
Cells(2, ActiveCell.Column).Select
Range(ActiveCell.Address, Cells(LastRow, ActiveCell.Column)).Select
Selection.Sort Key1:=Range("c_AD_ADATE"), Order1:=xlAscending, DataOption1:=xlSortTextAsNumbers
'
With ActiveWorkbook.Worksheets("AD").Sort
.SetRange Range("tbl_AD")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
ActiveWorkbook.Worksheets("AD").Sort.SortFields.Clear
Cells(1, ActiveCell.Column).Select
AutoFilter = False
'
'Cells(1, 1).Select
'ActiveCell.Offset(1, 0).Select
'Cells(1, 1).Select
'
End Sub