Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
JR JR is offline
external usenet poster
 
Posts: 92
Default Ranges in Custom Functions

Hi All,

I'm trying to Calculate a Custom Function in Excel, by passing in a range of
two cells rather than a cell name (which I had it working with previously).

An example is below:

Suppose in Excel I use:
=Invt_Bal(A1:D1,A2:D2)

With the function:

Function Invt_Bal(Opening as Range, Purchases as Range, Var2 as Range)
Dim Counter As Integer, UnitsCosted as Range

For Counter = 1 to StartCount.Rows.Count
Invt_Bal = Invt_Bal + Opening(Counter, 1) + Purchases (Counter,1) +
Var2(Counter,1)
Next Counter

The Actual code is longer than this, with approx 6 variables, which worked
fine when I was passing Names for the cells in, rather than the Cell
references.

When I had the names defined, my declarations we
Set Opening = Range("Opening_Bal")
Set Purchases = Range("Purchases")
Set Var2 = Range("Var2")

I'm not sure what to set these ranges to now or if?

Thanks for your help.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Ranges in Custom Functions

You shouldn't be setting them at all in either case. They are passed in as
ranges.

=Invt_Bal(Open_Bal,Purchases)

=Invt_Bal(A1:D1,A2:D2)


in a sample function

Function Invt_Bal(Opening as Range, Purchases as Range)
Invt_Bal = Opening.Address & ", " & Purchases.Address
End function

should return the same results.

as an example.

--
Regards,
Tom Ogilvy


"JR" wrote in message
...
Hi All,

I'm trying to Calculate a Custom Function in Excel, by passing in a range

of
two cells rather than a cell name (which I had it working with

previously).

An example is below:

Suppose in Excel I use:
=Invt_Bal(A1:D1,A2:D2)

With the function:

Function Invt_Bal(Opening as Range, Purchases as Range, Var2 as Range)
Dim Counter As Integer, UnitsCosted as Range

For Counter = 1 to StartCount.Rows.Count
Invt_Bal = Invt_Bal + Opening(Counter, 1) + Purchases (Counter,1) +
Var2(Counter,1)
Next Counter

The Actual code is longer than this, with approx 6 variables, which worked
fine when I was passing Names for the cells in, rather than the Cell
references.

When I had the names defined, my declarations we
Set Opening = Range("Opening_Bal")
Set Purchases = Range("Purchases")
Set Var2 = Range("Var2")

I'm not sure what to set these ranges to now or if?

Thanks for your help.




Reply
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
Using custom functions within custom validation Neil Excel Discussion (Misc queries) 4 December 14th 05 10:40 PM
if functions with more than 7 ifs (ranges are possible?) irwinko Excel Worksheet Functions 3 May 17th 05 12:57 PM
How to access ranges in closed workbooks in custom functions Deepak Agarwal Excel Programming 3 July 9th 04 01:59 PM
Functions and Ranges Robert Rosenberg[_2_] Excel Programming 0 December 30th 03 04:32 PM
Functions and Ranges Ian Mangelsdorf Excel Programming 1 December 3rd 03 07:02 AM


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

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

About Us

"It's about Microsoft Excel"