作者windknife18 (windknife18)
标题Re: [算表] vba 筛选排序请教大神哪里写错
时间Sun Sep 17 20:23:59 2023
不清楚为什麽要用筛选,如果只是要排序,不需要筛选喔
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
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 1.34.58.193 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Office/M.1694953441.A.6C0.html
1F:推 mini178: 谢谢大神 09/20 07:12
2F:→ windknife18: 不客气 :) 09/20 08:51