Re: [算表] vba 筛选排序请教大神哪里写错

楼主: windknife18 (windknife18)   2023-09-17 20:23:59
不清楚为什么要用筛选,如果只是要排序,不需要筛选喔
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
作者: mini178 (mini178)   2023-09-20 07:12:00
谢谢大神
楼主: windknife18 (windknife18)   2023-09-20 08:51:00
不客气 :)

Links booklink

Contact Us: admin [ a t ] ucptt.com