Reversing a list in Excel within a formula

前端 未结 4 770
刺人心
刺人心 2020-12-16 06:55

So there are a bunch of ways to reverse a list to turn it into a new list, using helper columns. I\'ve written some code that does use helper columns to reverse a list and t

4条回答
  •  伪装坚强ぢ
    2020-12-16 07:02

    Actually you can make the formula in your Question work (with a small UDF()):

    Pick a cell and enter:

    =SUMPRODUCT(reverse(A1:A3),B1:B3)
    

    with this in a standard module:

    Public Function reverse(rng As Range)
        Dim ary(), N As Long, i As Long
        N = rng.Count
        ReDim ary(1 To N)
        i = N
    
        For Each r In rng
            ary(i) = r.Value
            i = i - 1
        Next r
    
        With Application.WorksheetFunction
            reverse = .Transpose(ary)
        End With
    End Function
    

提交回复
热议问题