如题所述
Function BubbleSort1(ZHArray, XArray, YArray, ZArray As Variant)
'方法 2: 气泡排序。根据http://support.microsoft.com/网站提供的代码修改
'思路是根据一维数组排序,扩展到其他列也跟着排序,思路和单元格排序操作一致。
Dim temp As Variant
Dim temp1 As Variant
Dim Temp2 As Variant
Dim Temp3 As Variant
Dim i As Integer
Dim NoExchanges As Integer
Dim First As Integer, Last As Integer
First = LBound(ZHArray) '取数组上界
Last = UBound(ZHArray) '取数组下界
' Loop until no more "exchanges" are made.
Do
NoExchanges = True
' Loop through each element in the array.
For i = First To Last - 1
' If the element is greater than the element
' following it, exchange the two elements.
If ZHArray(i) > ZHArray(i + 1) Then
NoExchanges = False
temp = ZHArray(i) '桩号
ZHArray(i) = ZHArray(i + 1)
ZHArray(i + 1) = temp
temp1 = XArray(i) 'X坐标
Temp2 = YArray(i) 'Y坐标
Temp3 = ZArray(i) 'z坐标
XArray(i) = XArray(i + 1)
YArray(i) = YArray(i + 1)
ZArray(i) = ZArray(i + 1)
XArray(i + 1) = temp1
YArray(i + 1) = Temp2
ZArray(i + 1) = Temp3
End If
Next i
Loop While Not (NoExchanges)
End Function
'方法 2: 气泡排序。根据http://support.microsoft.com/网站提供的代码修改
'思路是根据一维数组排序,扩展到其他列也跟着排序,思路和单元格排序操作一致。
Dim temp As Variant
Dim temp1 As Variant
Dim Temp2 As Variant
Dim Temp3 As Variant
Dim i As Integer
Dim NoExchanges As Integer
Dim First As Integer, Last As Integer
First = LBound(ZHArray) '取数组上界
Last = UBound(ZHArray) '取数组下界
' Loop until no more "exchanges" are made.
Do
NoExchanges = True
' Loop through each element in the array.
For i = First To Last - 1
' If the element is greater than the element
' following it, exchange the two elements.
If ZHArray(i) > ZHArray(i + 1) Then
NoExchanges = False
temp = ZHArray(i) '桩号
ZHArray(i) = ZHArray(i + 1)
ZHArray(i + 1) = temp
temp1 = XArray(i) 'X坐标
Temp2 = YArray(i) 'Y坐标
Temp3 = ZArray(i) 'z坐标
XArray(i) = XArray(i + 1)
YArray(i) = YArray(i + 1)
ZArray(i) = ZArray(i + 1)
XArray(i + 1) = temp1
YArray(i + 1) = Temp2
ZArray(i + 1) = Temp3
End If
Next i
Loop While Not (NoExchanges)
End Function
温馨提示:答案为网友推荐,仅供参考
第1个回答 2013-11-13
有标题行用这样子,,以下以A列作列子
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
无标题行是这样子
Columns("A:A").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal追问
Columns("A:A").Select
Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal
无标题行是这样子
Columns("A:A").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlDescending, Header:=xlNo, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
:=xlPinYin, DataOption1:=xlSortNormal追问
你这就是用录制宏出来的,里面貌似有EXCEL自带的函数啊 我说的是完全用编程语言的,不带系统自带函数的 编程语句
追答那你遍历单元格吧,然后用气泡法进行排序就是了,这个是常用的简单排序方法
本回答被网友采纳第2个回答 2013-11-13
这种问题,建议你多学会使用“录制宏”,录制完毕,查看宏代码就知道了