本帖最后由 yaozong 于 2014-3-1 17:15 编辑
程式:(附件中含3种方法)
Sub 排序_结果复盖原数据()''程式之一
Sheets("Sheet1").Activate
Dim arr, i, j, m, n, x, y
[a3:b13].Sort [b3], 2
arr = [a3:b13].Value
x = UBound(arr)
ReDim brr(1 To UBound(arr), 1 To 2)
For i = 1 To UBound(arr)
If Len(arr(i, 1)) = 1 Then
y = y + 1
brr(y, 1) = arr(i, 1)
brr(y, 2) = arr(i, 2)
End If
Next
ReDim crr(1 To UBound(arr) + 1, 1 To 2)
For i = 1 To y
crr(i + m, 1) = brr(i, 1)
crr(i + m, 2) = brr(i, 2)
For j = 1 To UBound(arr)
If Len(arr(j, 1)) > 1 Then
If Left(arr(j, 1), 1) = brr(i, 1) Then
m = m + 1
crr(i + m, 1) = arr(j, 1)
crr(i + m, 2) = arr(j, 2)
End If
End If
Next
Next
[a3].Resize(UBound(arr), 2) = crr
End Sub |