注册 登录
编程论坛 VB6论坛

如何把vb正序代码改成倒序代码?

杨昇 发布于 2020-04-28 01:19, 1865 次点击
End Sub
Sub 排序()
'
' 宏2 宏
'

 Dim shthz As Worksheet
    Set shthz = Worksheets("汇总")
    Dim i As Integer, j As Integer, row As Integer
    Dim col As Integer, colstr As String
    col = shthz.Cells(1, 256).End(xlToLeft).Column
    colstr = getChar(col)

    If col > 82 Then
    MsgBox "统计的天数超过了80天,请删除最右边的数据,再运行程序!"
    Exit Sub
    End If
   
    row = shthz.Range("A65536").End(xlUp).row
   

    ActiveWorkbook.Worksheets("汇总").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("汇总").Sort.SortFields.Add Key:=Range("C2:C2860"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("汇总").Sort
        .SetRange Range("A1:" & colstr & row)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWindow.SmallScroll Down:=-6
End Sub
2 回复
#2
HVB62020-04-28 10:17
试试:
Sub 排序()
'
' 宏2 宏
'

 Dim shthz As Worksheet
    Set shthz = Worksheets("汇总")
    Dim i As Integer, j As Integer, row As Integer
    Dim col As Integer, colstr As String
    col = shthz.Cells(1, 256).End(xlToLeft).Column
    colstr = getChar(col)

    If col > 82 Then
    MsgBox "统计的天数超过了80天,请删除最右边的数据,再运行程序!"
    Exit Sub
    End If
   
    row = shthz.Range("A65536").End(xlUp).row
   

    ActiveWorkbook.Worksheets("汇总").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("汇总").Sort.SortFields.Add Key:=Range("C2:C2860"), _
        SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("汇总").Sort
        .SetRange Range("A1:" & colstr & row)
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    ActiveWindow.SmallScroll Down:=-6
End Sub
#3
杨昇2020-05-06 22:04
谢谢你,不过还是正序,没有改过来。
1