我有一个带有字母数字文本的 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
最佳答案
假设:
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,))
关于excel - 将字母数字文本按字母顺序排序 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72253389/