I am trying to sort data in a spreadsheet by three different values:
我试图通过三个不同的值对电子表格中的数据进行排序:
- Column F - Values - Oldest to Newest
- F列 - 值 - 从最新到最新
- Column B - Values - Smallest to Largest
- B栏 - 值 - 最小到最大
- Column A - Values - Z to A
- A列 - 值 - Z到A.
The code stops with an error on the .Apply section. I fear the cell selection is the issue.
代码在.Apply部分停止并出现错误。我担心细胞选择是个问题。
Sub DatePartOrderSort()
'
' DatePartOrderSort Macro
'
'
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(5, "A"), Cells(LR, "J")).Select
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
Cells(5, "A"), Cells(LR, "J")), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Date Order").Sort
.SetRange Range(Cells(5, "A"), Cells(LR, "J"))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
1 个解决方案
#1
2
Try this:
尝试这个:
Sub DatePartOrderSort()
'
' DatePartOrderSort Macro
'
'
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(5, "A"), Cells(LR, "J")).Select
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"F5:F" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"B5:B" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"A5:A" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Date Order").Sort
.SetRange Range(Cells(5, "A"), Cells(LR, "J"))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
#1
2
Try this:
尝试这个:
Sub DatePartOrderSort()
'
' DatePartOrderSort Macro
'
'
LR = Cells(Rows.Count, "A").End(xlUp).Row
Range(Cells(5, "A"), Cells(LR, "J")).Select
'
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"F5:F" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"B5:B" & LR), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets("Date Order").Sort.SortFields.Add Key:=Range( _
"A5:A" & LR), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Date Order").Sort
.SetRange Range(Cells(5, "A"), Cells(LR, "J"))
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub