I have this and it works, but I need it to sort on the specific range. It may not always be 39 rows down.
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("L12:L39") _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"AmEx,Discover,Master Card,Visa,Check", DataOption:=xlSortNormal
So I did this, but it still doesn't work.
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("L12", Selection.End(xlDown)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"AmEx,Discover,Master Card,Visa,Check", DataOption:=xlSortNormal
What am I doing wrong? I think this might be simple but I'm just not seeing it.
This is my full code for that part.
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("L12", Selection.End(xlDown)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"AmEx,Discover,Master Card,Visa,Check", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("J12", Selection.End(xlDown)) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("B11", Selection.End(xlDown))
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
It says 1004 the sort reference is not valid.
'*** Sorting by payment method
Range("L12").Select '*** Check this sorting for the correct cells
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("L12", Selection.End(xlDown)) _
, SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"AmEx,Discover,Master Card,Visa,Check", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("J12", Selection.End(xlDown)) _
, SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
Dim sht2 As Worksheet
Dim LastRow2 As Long
Dim LastColumn2 As Long
Dim StartCell2 As Range
Set sht2 = Worksheets("Sheet1")
Set StartCell2 = Range("B11")
Worksheets("Sheet1").UsedRange
LastRow2 = sht2.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
LastColumn2 = StartCell.SpecialCells(xlCellTypeLastCell).Column
sht2.Range(StartCell2, sht2.Cells(LastRow2, LastColumn2)).Select
With ActiveWorkbook.Worksheets("Sheet1").Sort
'.SetRange(StartCell2, sht2.Cells(LastRow2, LastColumn2)).Select
'.SetRange(StartCell2, sht2.Cells(LastRow2, LastColumn2)).Select
'.SetRange Range("B11", LastRow2)
.SetRange Range("B11:AA" & LastRow2)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Thanks.