【求助】VB或VBA高手
貌似问题出在 mi上如果k不等于二的话行交换,写出了个死循环,怎么改
Sub mysort()
Dim count As Long
Dim c, k
Dim g As Long, h As Long, t As Long
Dim w()
Dim z As Long, tt As Long
Dim i As Long, j As Long
Public mi As Long
mi = Selection.Rows.count
For i = 3 To mi - 1
k = i
Do While k <> 2 'exchange rows positions
If Cells(k, ni).Value < Cells(k - 1, ni) Then
For j = 1 To ni
c(j) = Cells(k, j)
Next j
For j = 1 To ni
Cells(k, j) = Cells(k - 1, j)
Next j
For j = 1 To ni
Cells(k - 1, j) = c(k, j)
Next j
k = k - 1
End If 请将这个子程序帖全:
Sub mysort()
...
End Sub
Posted by 陈酿 on 2011-10-13 10:11 http://www.ibmnb.com/images/common/back.gif
貌似问题出在 mi上
如果k不等于二的话行交换,写出了个死循环,怎么改
Sub mysort()
Dim count As Long
Dim c, k
Dim g As Long, h As Long, t As Long
Dim w ... for 为正循环 (负循环例如 for i = 3 to mi - 1 step -1), 所以 i >= 3 (或循环不执行,如果mi < 4的话)
由于 k = i, 所以 你这里的 k 不可能有 < 3的值出现, 所以 k <> 2 永远成立,是个死循环
For i = 3 To mi - 1
k = i
Do While k <> 2 'exchange rows positions 虽然我一直想学
但是貌似智商不够的样子
学不会。。 If Cells(k, ni).Value < Cells(k - 1, ni) Then
k = k -1 唉,看不懂~~^x^
页:
[1]