ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Passing a range to a user defined function (https://www.excelbanter.com/excel-discussion-misc-queries/150866-passing-range-user-defined-function.html)

Gary Nelson

Passing a range to a user defined function
 
This is probably going sound like a stupid question, but .....
I recently had occasion to write a VBA function for a workbook where one of
the arguments was supposed to be a range of cells, but when I try to use the
function by passing a range in the form of A1:E7, I get an error saying that
that argument is the wrong data type.
Do I need to refer to the range differently?
Was Range the wrong data type to use?

Jim Thomlinson

Passing a range to a user defined function
 
Something like this

Public function MySum(byval rng as Range) as double
MySum = Application.Sum(rng)
end function
--
HTH...

Jim Thomlinson


"Gary Nelson" wrote:

This is probably going sound like a stupid question, but .....
I recently had occasion to write a VBA function for a workbook where one of
the arguments was supposed to be a range of cells, but when I try to use the
function by passing a range in the form of A1:E7, I get an error saying that
that argument is the wrong data type.
Do I need to refer to the range differently?
Was Range the wrong data type to use?



All times are GMT +1. The time now is 09:49 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com