有3栏表格需要排序,请高人指点如何操作
发布网友
发布时间:2022-08-24 09:13
我来回答
共1个回答
热心网友
时间:2024-12-12 03:05
考虑一个排法:
Private Sub CommandButton1_Click()
i = 2
Do Until Cells(i, 1) = "" And Cells(i, 2) = "" And Cells(i, 3) = ""
If Cells(i, 1) = "" Then
If Cells(i, 2) = "" Then
Cells(i, 2) = Cells(i - 1, 2)
Cells(i, 1) = Cells(i - 1, 1)
Else
Cells(i, 3) = 9
Cells(i, 1) = Cells(i - 1, 1)
End If
Else
Cells(i, 2) = 9
End If
i = i + 1
Loop
Range(Cells(1, 1), Cells(i - 1, 3)).Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Key2:=Range("B1") _
, Order2:=xlAscending, Key3:=Range("C1"), Order3:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
SortMethod:=xlPinYin, DataOption1:=xlSortNormal, DataOption2:= _
xlSortNormal, DataOption3:=xlSortNormal
For j = 1 To 3
For k = i - 1 To 2 Step -1
If Cells(k, j) = Cells(k - 1, j) Then
Cells(k, j) = ""
End If
Next
Next
For k = 1 To i - 1
If Cells(k, 2) = 9 Then
Cells(k, 2) = ""
End If
Next
For k = 1 To i - 1
If Cells(k, 3) = 9 Then
Cells(k, 3) = ""
End If
Next
End Sub追问代码运行不了,可否中文解释下运行原理,或者加一下我的QQ 36808038 我给您具体文件实验。
追答就是A列空单元格填充上一行的值,B列也如此,所有单元格补充满数据,再对A、B、C列排序,排好后,去掉补充的数据。