You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VBA技术求助:将S1:S6数据移至T1并去重降序排序

Solution for Adding Descending Sort to Your Data Migration Code

Hey John, nice work getting the filtering and data migration part working! Let’s fix that missing sorting step for you.

Assuming you’re using Excel VBA for this task, here’s how to add the descending sort right after your existing filtering/migration code:

Step 1: Add Code to Define the Target Range

First, we need to find the last row with data in column T (since your filtered data starts at T1). Then we can sort that entire range.

Add this snippet after your existing Filter Result code:

' Find the last row with data in column T
Dim lastRow As Long
lastRow = Range("T" & Rows.Count).End(xlUp).Row

' Sort the target range (T1 to T[lastRow]) in descending order
Range("T1:T" & lastRow).Sort _
    Key1:=Range("T1"), _
    Order1:=xlDescending, _
    Header:=xlNo ' Change to xlYes if T1 is a header row, not data

Quick Explanation:

  • lastRow calculates the bottom-most row with data in column T, so we don’t accidentally sort empty cells.
  • The Sort method targets your filtered data range:
    • Key1:=Range("T1") tells Excel to sort based on values in column T.
    • Order1:=xlDescending sets the sort order from highest to lowest.
    • Header adjusts whether Excel treats the first row as a header (use xlYes if T1 is a label, not a number; keep xlNo if T1 is your first data point).

If you were using Excel formulas instead of VBA, you could even combine the deduplication and sorting in one step with:

=SORT(UNIQUE(S1:S6), , -1)

Just paste that into cell T1, and it’ll automatically output the sorted, unique values from S1:S6.

Hope this gets you sorted out (pun intended)! 😊

内容的提问来源于stack exchange,提问作者JonhDoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:13:23