不清楚为什么要用筛选,如果只是要排序,不需要筛选喔
Sub 筛选和排序()
Dim ws As Worksheet
Dim lastRow As Long
Dim filterRowStart As Long
Dim filterRowEnd As Long
' 定义工作表
Set ws = ThisWorkbook.Sheets("20230918盘前")
' 确定最后一行
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 找到第一个出现"投本比1日"的上一列
For filterRowStart = 2 To lastRow
If ws.Cells(filterRowStart, 1).Value = "投本比1日" Then
Exit For
End If
Next filterRowStart
' 找到最后一个出现"投本比1日"的列
For filterRowEnd = lastRow To 2 Step -1
If ws.Cells(filterRowEnd, 1).Value = "投本比1日" Then
Exit For
End If
Next filterRowEnd
' 如果找到"投本比1日",则应用AutoFilter
If filterRowStart <= lastRow And filterRowEnd >= filterRowStart Then
' 排序投本比1日%
ws.Rows(filterRowStart & ":" & filterRowEnd).Sort _
key1:=Range("J" & filterRowStart), Order1:=xlDescending, Header:=xlNo
End If
End Sub