Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
nox nox is offline
external usenet poster
 
Posts: 2
Default function with a range as a parameter

Hi all,

I am trying to write a function that uses a range as a parameter (see below)

Function Param(MyRange As Range, Aline As Integer) As Integer
Param = 5
End Function

The problem is that when the range specifies cells on a closed workbook,
the function dispays an error (#VALUE)
If the range corresponds to an open workbook there is no error.

Is it possible to get back a Range on a closed workbook (like the function
VLOOKUP does) ?
if yes how ?

Thanks

Jim.

(I am using Excel 2000)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default function with a range as a parameter

VBA doesn't support referencing closed workbooks.

John Walkenbach documents a method useing the xl4 macro in VBA:

http://www.j-walk.com/ss/excel/tips/tip82.htm

I have found it quicker to put a linking formula in a cell to retrieve the
value, then clear it out if necessary. (this wouldn't work in a UDF used in
a worksheet)

--
Regards,
Tom Ogilvy


"nox" wrote:

Hi all,

I am trying to write a function that uses a range as a parameter (see below)

Function Param(MyRange As Range, Aline As Integer) As Integer
Param = 5
End Function

The problem is that when the range specifies cells on a closed workbook,
the function dispays an error (#VALUE)
If the range corresponds to an open workbook there is no error.

Is it possible to get back a Range on a closed workbook (like the function
VLOOKUP does) ?
if yes how ?

Thanks

Jim.

(I am using Excel 2000)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default function with a range as a parameter

Any function that references a closed workbook (even vlookup) needs to have
the workbook open to get the data. If you need it to work every time, you
probably ought to build a UDF that opens the workbook in question, accesses
the data and then closes the workbook. Of course, every time the workbook is
calculated, all of the external workbooks will need to be opened/closed and
it could take some time.
--
HTH,
Barb Reinhardt



"nox" wrote:

Hi all,

I am trying to write a function that uses a range as a parameter (see below)

Function Param(MyRange As Range, Aline As Integer) As Integer
Param = 5
End Function

The problem is that when the range specifies cells on a closed workbook,
the function dispays an error (#VALUE)
If the range corresponds to an open workbook there is no error.

Is it possible to get back a Range on a closed workbook (like the function
VLOOKUP does) ?
if yes how ?

Thanks

Jim.

(I am using Excel 2000)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default function with a range as a parameter

=vlookup() can retrieve data from a closed workbook.

Lots of functions can. But you're right, some functions can't (like
=indirect(), =sumif(), =countif()).

Barb Reinhardt wrote:

Any function that references a closed workbook (even vlookup) needs to have
the workbook open to get the data. If you need it to work every time, you
probably ought to build a UDF that opens the workbook in question, accesses
the data and then closes the workbook. Of course, every time the workbook is
calculated, all of the external workbooks will need to be opened/closed and
it could take some time.
--
HTH,
Barb Reinhardt

"nox" wrote:

Hi all,

I am trying to write a function that uses a range as a parameter (see below)

Function Param(MyRange As Range, Aline As Integer) As Integer
Param = 5
End Function

The problem is that when the range specifies cells on a closed workbook,
the function dispays an error (#VALUE)
If the range corresponds to an open workbook there is no error.

Is it possible to get back a Range on a closed workbook (like the function
VLOOKUP does) ?
if yes how ?

Thanks

Jim.

(I am using Excel 2000)



--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
nox nox is offline
external usenet poster
 
Posts: 2
Default function with a range as a parameter

Thanks Tom,

It's a pity that VBA does not support referencing closed workbook while
VLOOKUPS does.

"Tom Ogilvy" wrote:

VBA doesn't support referencing closed workbooks.

John Walkenbach documents a method useing the xl4 macro in VBA:

http://www.j-walk.com/ss/excel/tips/tip82.htm

I have found it quicker to put a linking formula in a cell to retrieve the
value, then clear it out if necessary. (this wouldn't work in a UDF used in
a worksheet)

--
Regards,
Tom Ogilvy



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
Function with parameter "as range" Mike Archer Excel Programming 4 February 2nd 06 05:32 PM
Format when sending a range as parameter to a custom function George Furnell Excel Programming 2 December 1st 05 05:22 PM
user defined function receiving a range as parameter Marc Excel Programming 7 October 14th 05 07:50 PM
Excel2000: Reading values from range, passed to function as parameter using an expression Arvi Laanemets Excel Programming 3 April 29th 05 02:34 PM
Defining new function with cell range parameter NormD Excel Programming 2 March 1st 05 03:21 PM


All times are GMT +1. The time now is 01:00 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"