Hi all. I can think of at least two other ways to do this.
And I'm sure there are many more. I'm curious why I've never seen a range starting with ActiveCell and why it doesn't work. I have "guess' " but honestly I struggle to keep objects etc, straight. I'm a hack and freely admit it.
The column is one in a series I want to sort 1st simply to not have any empty or not really empty cells before I convert a text "10-12-31" into a usable date value:
As always, thanks much to those who give so freely of their time. I do try to pay it forward.
Ron
- I can sort the columns so I know the column number
- I can find the cell, select the column, create a named range and sort on that.
And I'm sure there are many more. I'm curious why I've never seen a range starting with ActiveCell and why it doesn't work. I have "guess' " but honestly I struggle to keep objects etc, straight. I'm a hack and freely admit it.
The column is one in a series I want to sort 1st simply to not have any empty or not really empty cells before I convert a text "10-12-31" into a usable date value:
Code:
Sub tm_SelectSortCol()
'
' tm_RemoveBtn Macro
'
On Error GoTo Whoa
'
'
Application.Volatile True
Dim LastRow As Long
Dim lastCol As Integer
Dim rng As Range
Dim thiswksht As Worksheet
Dim thiswb As Workbook
'
'
'Worksheets("PIV").Activate
Set thiswksht = 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
'
thiswksht.Sort.SortFields.Clear
'
Range("A1").Activate
Cells.Find(What:="ACTIVATION DATE", After:=ActiveCell, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Select
thiswksht.Sort.SortFields.Add Key:=Range(ActiveCell, Cells(ActiveCell, LastRow)), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
With thiswksht.Sort
.SetRange Range("A1", Cells(LastRow, lastCol))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
'
Whoa:
MsgBox "Error " & Err.Number & " " & Err.Description, vbOKOnly
'
End Sub
As always, thanks much to those who give so freely of their time. I do try to pay it forward.
Ron