|
对当前光标所在的行进行横向排序。
Sub SortByRow()
'**********************
' 2006-11-21 Aaron
'**********************
Dim Ld(1 To 255) As Variant, I, J As Integer
Dim Mvalue As Variant, MI As Integer, Crow As Long, Ccol As Integer
Crow = ActiveCell.Row 'Get current row no.
Ccol = Cells(Crow, 255).End(xlToLeft).Column 'Get urrent row range last column no.
For I = 1 To Ccol - 1
Mvalue = Cells(Crow, I).Value 'Save first cell value to variant
MI = I 'Save column no. to variant
For J = I + 1 To Ccol
If Cells(Crow, J).Value < Mvalue Then 'if latter cell value less than var Mvalue, replace it
Mvalue = Cells(Crow, J).Value
MI = J
End If
Next J
Cells(Crow, MI).Value = Cells(Crow, I).Value 'exchange the minimal cells' value
Cells(Crow, I).Value = Mvalue
Next I
If Len(Cells(Crow, 1)) = 0 Then
Range(Cells(Crow, 1), Cells(Crow, Cells(Crow, 1).End(xlToRight).Column - 1)).Delete Shift:=xlToLeft 'Delete blank cell in head column
End If
End Sub |
|