按4个条件排序EXCEL表
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Option Explicit
Sub an_4c1d_sort(sheet As Worksheet, c1 As Integer, c2 As Integer, c3 As Integer, c4 As Integer, d1 As V ariant, qsh_row As Integer)
''''''''''''''''''''''''''''
Dim sort_c1 As Variant
Dim sort_c2 As Variant
Dim sort_c3 As Variant
Dim sort_c4 As Variant
Dim sort_d1 As Variant
Dim p As Integer
Dim H As Integer
Dim loop_true As Boolean
Dim swap_flag As Boolean
Dim sheet_max_row_count As Integer
sheet_max_row_count = sheet.Cells.SpecialCells(xlCellTypeLastCell).Row
For p = (qsh_row + 1) To sheet_max_row_count
sort_c1 = sheet.Cells(p, c1)
sort_c2 = sheet.Cells(p, c2)
sort_c3 = sheet.Cells(p, c3)
sort_c4 = sheet.Cells(p, c4)
sort_d1 = sheet.Cells(p, d1)
swap_flag = False
H = p - 1
'z
If p = qsh_row + 1 Then
'1
If sheet.Cells(H, c1) = sheet.Cells(p, c1) Then
'2
If sheet.Cells(H, c2) = sheet.Cells(p, c2) Then
'3
If sheet.Cells(H, c3) = sheet.Cells(p, c3) Then
'4
If sheet.Cells(H, c4) > sheet.Cells(p, c4) Then
swap_flag = True
End If '4
'3
Else
'33
If sheet.Cells(H, c3) > sheet.Cells(p, c3) Then
swap_flag = True
End If '33
End If '3
'2
Else
'22
If sheet.Cells(H, c2) > sheet.Cells(p, c2) Then
swap_flag = True
End If '22
End If '2
'1
Else
'11
If sheet.Cells(H, c1) > sheet.Cells(p, c1) Then
swap_flag = True
End If '11
End If '1
If swap_flag = True Then
sheet.Cells(p, c1) = sheet.Cells(H, c1)
sheet.Cells(p, c2) = sheet.Cells(H, c2)
sheet.Cells(p, c3) = sheet.Cells(H, c3)
sheet.Cells(p, c4) = sheet.Cells(H, c4)
sheet.Cells(p, d1) = sheet.Cells(H, d1)
sheet.Cells(H, c1) = sort_c1
sheet.Cells(H, c2) = sort_c2
sheet.Cells(H, c3) = sort_c3
sheet.Cells(H, c4) = sort_c4
sheet.Cells(H, d1) = sort_d1
End If
'z
Else
loop_true = True
While loop_true And H >= qsh_row
'1
If sheet.Cells(H, c1) = sort_c1 Then
'2
If sheet.Cells(H, c2) = sort_c2 Then
'3
If sheet.Cells(H, c3) = sort_c3 Then
'4
If sheet.Cells(H, c4) > sort_c4 Then
swap_flag = True
End If '4
'3
Else
'33
If sheet.Cells(H, c3) > sort_c3 Then
swap_flag = True
End If '33
End If '3
'2
Else
'22
If sheet.Cells(H, c2) > sort_c2 Then
swap_flag = True
End If '22
End If '2
'1
Else
'11
If sheet.Cells(H, c1) > sort_c1 Then
swap_flag = True
End If '11
End If '1
If swap_flag = True Then
sheet.Cells(H + 1, c1) = sheet.Cells(H, c1)
sheet.Cells(H + 1, c2) = sheet.Cells(H, c2)
sheet.Cells(H + 1, c3) = sheet.Cells(H, c3)
sheet.Cells(H + 1, c4) = sheet.Cells(H, c4)
sheet.Cells(H + 1, d1) = sheet.Cells(H, d1)
swap_flag = False
If H = qsh_row Then
sheet.Cells(H, c1) = sort_c1
sheet.Cells(H, c2) = sort_c2
sheet.Cells(H, c3) = sort_c3
sheet.Cells(H, c4) = sort_c4
sheet.Cells(H, d1) = sort_d1
loop_true = False
Else
H = H - 1
End If
Else
sheet.Cells(H + 1, c1) = sort_c1