Working with named ranges in UDFs

JenniferMurphy

Well-known Member
Joined
Jul 23, 2011
Messages
2,531
Office Version
  1. 365
Platform
  1. Windows
I would like to to do some fairly complicated calculations in a UDF. And I would like to do them using named ranges, if possible.

Here's a sample table. The input data is in Columns D, E, & F. These columns have been assigned the names T, A, & B. Column G contains the calculated result. The formulas in Column G are shown in Column H. Each result in G is calculated from the data in the 2x3 range of cells in Columns D, E, & F and the current row plus the previous row. For example, the data in G4 is calculated from the data in cells D4:F5. For the last row, the "previous" row is the top row, so the value in G8 is calculated from the data in cells D8:F8 & D4:F4.

R/CCDEFGHIJ
3#TABXFormula in Col GUDFOriginal Equation
4582.422033.52=(D4*F5-D5*F4)/(E4*F5-E5*F4)=MyUDF(T,A,B)=(T4*B5 - T5*B4)/(A4*B5 - A5*B4)
5433.09630.99=(D5*F6-D6*F5)/(E5*F6-E6*F5)=MyUDF(T,A,B)=(T5*B6 - T6*B5)/(A5*B6 - A6*B5)
6335.07833.77=(D6*F7-D7*F6)/(E6*F7-E7*F6)=MyUDF(T,A,B)=(T6*B7 - T7*B6)/(A6*B7 - A7*B6)
7227.54633.65=(D7*F8-D8*F7)/(E7*F8-E8*F7)=MyUDF(T,A,B)=(T7*B8 - T8*B7)/(A7*B8 - A8*B2)
8116.61333.87=(D8*F4-D4*F8)/(E8*F4-E4*F8)=MyUDF(T,A,B)=(T8*B4 - T4*B8)/(A8*B4 - A4*B8)

<tbody>
</tbody>

Column I shows the UDF call I would like to be able to make. Column J shows the original equation that I am trying to implement. I would like the code in the UDF to look as much like that equation as possible.

If I could make the code in the sheet look like that equation, I probably wouldn't need the UDF.

Note that the results are added from the bottom up. New results are added at the top.

Thanks for any help...
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,214,823
Messages
6,121,780
Members
449,049
Latest member
greyangel23

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