Sub sortbyCol()
[A1:I1] = Array("8", "4", "1", "3", "2a", "2b", "6", "5", "7")
With [A1].CurrentRegion
.Sort [A1], xlAscending, , , , , , xlNo, , , xlSortColumns
End With
End Sub
Sub sortbyCol()
[A1:I1] = Array("8", "4", "1", "3", "2a", "2b", "6", "5", "7")
ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range( _
"A1:I1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortTextAsNumbers
With ActiveWorkbook.ActiveSheet.Sort
.SetRange Range("A1:I25")
.Header = xlGuess
.MatchCase = False
.Orientation = xlLeftToRight
.SortMethod = xlPinYin
.Apply
End With
End Sub
PHP:Sub sortbyCol() [A1:I1] = Array("8", "4", "1", "3", "2a", "2b", "6", "5", "7") With [A1].CurrentRegion .Sort [A1], xlAscending, , , , , , xlNo, , , xlSortColumns End With End Sub
Tôi thử gán mảng trên vào [A1:I1] và thử sort theo cột (nghĩa là sắp xếp cột A --> I lại theo số thứ tự đánh trên mảng nhưng bị lỗi
Các bác xem và chỉ giúp nhé
Sub sortbyCol()
With Range("A1:I1")
.Value = Array("8", "4", "1", "3", "2a", "2b", "6", "5", "7")
.Sort .Rows(1), 1, , , , , , , xlNo, , , xlLeftToRight
End With
End Sub
Vầy thử xem:
PHP:Sub sortbyCol() With Range("A1:I1") .Value = Array("8", "4", "1", "3", "2a", "2b", "6", "5", "7") .Sort .Rows(1), 1, , , , , , , xlNo, , , xlLeftToRight End With End Sub
Range("A1:I1").rows(1)
Không hẳn vậy!Tức là phải thay [A1] bằng
PHP:Range("A1:I1").rows(1)
Code ngắn nhỉ bác NDU? nhưng hơi lạ code sort theo column lại thêm cái ông .rows(1)...^_ (thay vì [A1]...chắc chỉ dành cho sort by rows
kì ta?
Cám ơn NDU nhiều