以下是引用lg_cai在2006-1-24 23:10:39的发言:
我来一段,排序用代码实现
Sub px() n = [a1].End(xlDown).Row arr = Range("a1:a" & n) i = 1 Do Change = False For j = 1 To n - i If arr(j, 1) > arr(j + 1, 1) Then arr(j, 1) = arr(j, 1) + arr(j + 1, 1) arr(j + 1, 1) = arr(j, 1) - arr(j + 1, 1) arr(j, 1) = arr(j, 1) - arr(j + 1, 1) Change = True End If Next j i = i + 1 Loop Until i = n Or Not Change s = "" For j = 2 To n If arr(j, 1) - arr(j - 1, 1) = 2 Then s = IIf(s = "", s, s & ",") & arr(j, 1) - 1 ElseIf arr(j, 1) - arr(j - 1, 1) > 2 Then s = IIf(s = "", s, s & ",") & arr(j - 1, 1) + 1 & "-" & arr(j, 1) - 1 End If Next j MsgBox s End Sub
代码结果为“7-9,15,19-20,26-29”,不正确 - taller
没错呀,现上传附件,请指正
fsNlUmnm.rar
(10.09 KB, 下载次数: 47)
|