我想你所遇到的問題是,你是排序entire column
,而不是定義數據範圍的結束。
見下文:
Dim ws as Worksheet
Set ws = Worksheets("Sheet1") 'change as needed
With ws
Dim lRow as Long
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A1:N" & lRow).Sort Key1:=.Range("A1:A" & lRow), _
Order1:=xlAscending, Header:= xlGuess, OrderCustom:=1, _
MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End With
如果你有XL 2007或更高,這可能是要走的路:
Dim ws as Worksheet
Set ws = Worksheets("Sheet1") 'change as needed
With ws
Dim lRow as Long
lRow = .Range("A" & .Rows.Count).End(xlUp).Row
With .Sort
With .SortFields
.Clear
.Add Key:=.Range("A1:A" & lRow), SortOn:=xlValues, _
Order:=xlAscending, DataOption:=xlSortNormal
End With
.SetRange .Range("A1:N" & lRow)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
THANK YOU SO MUCH!第一個是修理先生! –
我似乎無法找到如何標記爲答案:/ –
哇...我覺得愚蠢,哈!虛幻。再次感謝你。 –