【发布时间】:2021-11-10 15:58:07
【问题描述】:
我有一些个人数据需要 VBA 按标题名称排序,但有时其中一个标题不存在,我需要它来跳过代码块并按不同的标题名称排序。另外,我只能弄清楚如何做三列而不是四列,所以如果有人能帮我解决这个问题,那就太棒了!
我需要它升序排序:
Grade, Teacher, Last Name, First Name
-要么-
Grade, Last Name, First Name
Dim Fnd(1 To 3) As Range
Dim Ary As Variant
Dim i As Long
Ary = Array("Grade", "Teacher", "Last Name")
For i = 1 To 3
Set Fnd(i) = Range("1:1").Find(Ary(i - 1), , , xlWhole, , , False, , False)
Next i
Range("A1").CurrentRegion.Sort _
key1:=Fnd(1), order1:=xlAscending, _
key2:=Fnd(2), order2:=xlAscending, _
key3:=Fnd(3), order3:=xlAscending, _
Header:=xlYes
【问题讨论】: