我有一個帶有字母數字文本的 excel 表格,如圖所示:

我想將自定義排序串列的所有行排序為(“無線”、“座機”、“VOIP”),
vba 代碼作業但它的排序資料為數字,而我想按字母順序排序資料并忽略數字請告訴我解決方案。
Sub SortIndividualR()
'Updateby Extendoffice
Dim xRg As Range, yRg As Range, vCustom_Sort As Variant, rr As Long
vCustom_Sort = Array("Wireless", "Landline", "VOIP", Chr(42))
Application.AddCustomList ListArray:=vCustom_Sort
If TypeName(Selection) <> "Range" Then Exit Sub
Set xRg = Selection
If xRg.Count = 1 Then
MsgBox "Select multiple cells!", vbExclamation, "Kutools for Excel"
Exit Sub
End If
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
Application.ScreenUpdating = False
For Each yRg In xRg.Rows
yRg.NumberFormat = "@"
yRg.Sort Key1:=yRg.Cells(1, 1), Order1:=xlAscending, _
Orientation:=xlSortRows, Header:=xlYes, MatchCase:=False, _
OrderCustom:=Application.CustomListCount 1
Next yRg
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
End With
Application.ScreenUpdating = True
End Sub
uj5u.com熱心網友回復:
假設:
- 每個單元格中存在這三個選項之一;
- 每個單元格的格式根據您的示例資料;
- 您不需要 VBA 本身;
- 訪問 ms365。

中的公式F1:
=LET(X,TOROW(A1:D1,1),SORTBY(X,FIND(MID(X,18,1),"WLV"),,X,))
我選擇按您的自定義范圍進行第一次排序,然后按實際的數字字串進行第二次排序。
如果您沒有訪問權限TOROW(),您可以更改為FILTER():
=LET(X,FILTER(A1:D1,A1:D1<>""),SORTBY(X,FIND(MID(X,18,1),"WLV"),,X,))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/475611.html
