LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default Passing a named range into a user defined function

Hi,

i have written my first user defined function as follows:

Function Budget_Amount(Spread_Method As String, _
Annual_Amount As Currency, _
Budget_Month As Integer, _
Manual_Percent As Currency, _
Manual_Amount As Currency, _
Manual_Override As String, _
Rounding_Month As Integer, _
Rounding_Factor As Integer)

Dim Source_Cell As Range

If Annual_Amount = 0 Then
Budget_Amount = 0
Else
If Rounding_Month = Budget_Month Then
Dim x As Integer
Set Source_Cell = Application.Caller
Budget_Amount = Annual_Amount
For x = 1 To 12
If x < Rounding_Month Then
Budget_Amount = Budget_Amount - _
Source_Cell.Cells(1, x + 1 - Rounding_Month).Value
End If
Next x
Else
Select Case UCase(Spread_Method)
Case "MP"
Budget_Amount = Annual_Amount * Manual_Percent
Case "MA"
Budget_Amount = Manual_Amount
Case ""
Budget_Amount = "Spread Required"
Case Else
If Left(UCase(Manual_Override), 1) = "Y" _
And Manual_Amount < 0 Then
Budget_Amount = Manual_Amount
Else
With WorksheetFunction
Budget_Amount = Annual_Amount * _
.Index(Range("Spread_Percent_" & Budget_Month), _
.Match(Spread_Method, _
Range("Spread_IDs"), 0))
End With
End If
End Select
Budget_Amount = WorksheetFunction.Round(Budget_Amount,
Rounding_Factor)
End If
End If

End Function
-----------------------------------
the function works when I enter it into a cell as follows:

=budget_amount($G13,$H13,I$4,AS13,BH13,BG13,Roundi ng_Month,Rounding_factor)

the named ranges Rounding_Month and Rounding_factor are single cell named
ranges. However, I want to be able to use named ranges for all other
variables being passed to the function, i.e. $G13, $H13, etc... where I would
replace $G13 with the named range Selected_Spread_Method which = "B:B" and
$H13 = Annual_Amount = "C:C"

If I use regular excel functions, I can reference a named range like
Annual_Amount, and it knows to use the amount from the same row as the
formula. How can I get my function to act this way?

things I have tried:
- changing the variable types from String to Range
- then I tried finding the intersection of the range and the caller cell.

Ideas?

thanks

Simon

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array in a user defined function Peter M Excel Programming 5 June 27th 08 10:45 PM
Passing a range to a user defined function Gary Nelson Excel Discussion (Misc queries) 1 July 19th 07 04:22 PM
passing named range to a UDF user defined function Brian Murphy Excel Programming 3 June 13th 04 08:38 PM
passing a range to a user defined function using a form davek Excel Programming 1 December 24th 03 07:40 AM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"