Get AutoFilter sort criteria and apply on second sheet

前端 未结 3 446
生来不讨喜
生来不讨喜 2020-12-22 04:47

I\'m trying to see if I can programatically trap an AutoFilter sort event, get the sort criteria and then apply that same sort criteria to an AutoFilter in a second workshee

3条回答
  •  悲哀的现实
    2020-12-22 05:21

    Here are some notes on what I see as your requirements.

    Dim rv As AutoFilter ''Object
    Set rv = Sheet1.AutoFilter
    
    ''Just for curiosity
    Debug.Print rv.Sort.Header
    Debug.Print rv.Sort.SortFields.Count
    Debug.Print rv.Sort.SortFields.Item(1).SortOn
    Debug.Print rv.Sort.Rng.Address
    Debug.Print rv.Sort.SortFields.Item(1).Key.Address
    
    ''One key only, but it is easy enough to loop and add others
    Sheet2.Range(rv.Sort.Rng.Address).Sort _
        key1:=Sheet2.Columns(rv.Sort.SortFields(1).Key.Column), _
        Header:=xlYes
    

提交回复
热议问题