VBA Excel sort range by specific column

后端 未结 3 425
名媛妹妹
名媛妹妹 2020-11-30 02:26

I have a table that can contain any number of rows:

\"enter

As I said it can c

相关标签:
3条回答
  • 2020-11-30 02:45

    Or this:

    Range("A2", Range("D" & Rows.Count).End(xlUp).Address).Sort Key1:=[b3], _
        Order1:=xlAscending, Header:=xlYes
    
    0 讨论(0)
  • 2020-11-30 03:00

    Try this code:

    Dim lastrow As Long
    lastrow = Cells(Rows.Count, 2).End(xlUp).Row
    Range("A3:D" & lastrow).Sort key1:=Range("B3:B" & lastrow), _
       order1:=xlAscending, Header:=xlNo
    
    0 讨论(0)
  • 2020-11-30 03:10

    If the starting cell of the range and of the key is static, the solution can be very simple:

    Range("A3").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Sort key1:=Range("B3", Range("B3").End(xlDown)), _
    order1:=xlAscending, Header:=xlNo
    
    0 讨论(0)
提交回复
热议问题