简体   繁体   中英

VBA Sort A-Z on One Column

我如何根据MI列上的AZ升序对所有具有AZ的行进行排序,但尝试了以下操作,但仍无法理解我可能做错了什么?

Range("A1", Range("Z" & Rows.Count).End(xlUp)).Sort [M1], xlAscending

Record a macro where you select the column you want to be sorted. As an example, I've recorded a macro that sorts column M in ascending order:

Sub SortAsc2()

Dim LastRow As Long

LastRow = Cells(Rows.Count, "M").End(xlUp).Row

Columns("M:M").Select
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("M1"), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange Range("M1:M" & LastRow)
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM