Excel [求助]用1个vba在两个单元格做两种排序 - ExcelVBA程序开发 - ...

来源:百度文库 编辑:神马文学网 时间:2024/04/29 20:34:28

Private Sub Worksheet_Change(ByVal Target As Range)
 If replace(activecell.address,"$","")= "C2" Then
    Range("A4:G31").Select
    Selection.Sort Key1:=Range("C4"), Order1:=xlDescending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, SortMethod _
        :=xlPinYin, DataOption1:=xlSortNormal
 elseif replace(activecell.address,"$","")= "C38" Then
    Range("A40:G67").Select
    Selection.Sort Key1:=Range("C40"), Order1:=xlDescending, Header:=xlGuess _
        , OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        SortMethod:=xlPinYin, DataOption1:=xlSortNormal
   End If
End Sub

range的activate是方法,不是属性