0
好吧,所以我有一個通常按稀有排序的項目列表,但對於一個特定的操作,我需要對它進行排序,以便匹配函數可以對其進行排序,所以我設置了它直到爲匹配函數進行排序,然後將其恢復。然而,匹配函數正在提取排序之前的行。有誰知道這可能會如何解決?代碼如下(我包括龐大的排序代碼):Excel VBA匹配函數忽略更新排序
'Sort for Match Function
Sheets("Item List").Select
Range("L2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("L2:U2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Item List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Item List").Sort.SortFields.Add Key:=Range(_
"L2:L300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Item List").Sort
.SetRange Range("L1:U300")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Dim x As Integer
x = Application.Match(BuyItem.Value, Range("TraderItems"))
MsgBox (x)
'Sort back to Rarity
Sheets("Item List").Select
Range("L2").Select
Range(Selection, Selection.End(xlToRight)).Select
Range("L2:U2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("Item List").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Item List").Sort.SortFields.Add Key:=Range(_
"R2:R300"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("Item List").Sort
.SetRange Range("L1:U300")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
替換'實際範圍TraderItems'。 –
什麼是Range(「TraderItems」))?你有一個名爲範圍「TraderItems」?你在哪裏設置它? –
此外,如果您已經計算過,請嘗試在排序後在其中放置強制計算範圍... – TheSilkCode