看板 Office 關於我們 聯絡資訊
不清楚為什麼要用篩選,如果只是要排序,不需要篩選喔 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://www.ptt.cc/bbs/Office/M.1694953441.A.6C0.html
mini178: 謝謝大神 09/20 07:12
windknife18: 不客氣 :) 09/20 08:51