UDF needed! Reverse Range/Array Order, then SUMPRODUCT

mbp257

New Member
Joined
Feb 9, 2015
Messages
11
I need help creating a UDF to add multiple projects together at discrete points in their life cycle. Each project has the same production forecast.

Please see table below (btw, this is my first time posting on this forum so please let me know if another format is more helpful)

A few notes:
• Column A contains a typical production amount
• Column B contains the schedule or number of projects per period
• Column C represents what linking the cells manually looks like
• Column D contains an excel formula and works correctly but is confusing for others at my company, hence the desire to create a clean, two-argument function

What I imagine the UDF needs to do is first reverse one of the ranges in column A or B, then apply a SUMPRODUCT or equivalent code.

[TABLE="class: grid, width: 700"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]'Type' Amount[/TD]
[TD]Schedule[/TD]
[TD]Manual[/TD]
[TD]Formula[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]100[/TD]
[TD]1[/TD]
[TD]100[/TD]
[TD]100[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]90[/TD]
[TD]0[/TD]
[TD]90[/TD]
[TD]90[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]80[/TD]
[TD]2[/TD]
[TD]280[/TD]
[TD]280[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]70[/TD]
[TD]1[/TD]
[TD]=B2*A5+B3*A4+B4*A3+B5*A2[/TD]
[TD]=SUMPRODUCT(A$2:A5,
N(OFFSET($B$2:$B5,
ROWS($B$2:$B5)-
ROW($B$2:$B5)+
ROW($B$2)-1,0)))[/TD]
[/TR]
</tbody>[/TABLE]

Appreciate the help!
 
A little more compact...
Code:
Function RevSumProduct(Rng1 As Range, Rng2 As Range) As Variant
  RevSumProduct = Evaluate(Replace("SUMPRODUCT(" & Rng1.Address & ",N(OFFSET(@,ROWS(" & _
                  "@)-ROW(@)+ROW(" & Rng2(1).Address & ")-1,0)))", "@", Rng2.Address))
End Function

Thank you Rick, I originally tried doing it in a similar way but was spinning my wheels and using WorksheetFunction.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top