ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   User Defined Function - Using Cell Range (https://www.excelbanter.com/excel-programming/388600-user-defined-function-using-cell-range.html)

I need help please

User Defined Function - Using Cell Range
 
Hello,
I have a question about creating a user defined function...

I want it to make some calculations based off of static cell ranges. I was
hoping I could use either a named range, or just type in a static range in
the function.

Like, how would I do WorksheetFunction.SUM(RANGE) in a UDF?

RB Smissaert

User Defined Function - Using Cell Range
 
Function SumRange(rng As Range) As Double

SumRange = Application.WorksheetFunction.Sum(rng)

End Function


Sub test()

MsgBox SumRange(Range(Cells(1), Cells(3, 2)))

End Sub


RBS

"I need help please" wrote in
message ...
Hello,
I have a question about creating a user defined function...

I want it to make some calculations based off of static cell ranges. I
was
hoping I could use either a named range, or just type in a static range in
the function.

Like, how would I do WorksheetFunction.SUM(RANGE) in a UDF?



Vergel Adriano

User Defined Function - Using Cell Range
 
something like this will give the sum of A1:A10 in Sheet1

Dim dblSum As Double
dblSum = WorksheetFunction.Sum(Sheets("Sheet1").Range("A1:A 10"))

to use a named range, you can do it this way

dblSum = WorksheetFunction.Sum(Range("NamedRange"))



--
Hope that helps.

Vergel Adriano


"I need help please" wrote:

Hello,
I have a question about creating a user defined function...

I want it to make some calculations based off of static cell ranges. I was
hoping I could use either a named range, or just type in a static range in
the function.

Like, how would I do WorksheetFunction.SUM(RANGE) in a UDF?


I need help please

User Defined Function - Using Cell Range
 
Thanks - the Sheets("Sheet1").Range("A1:A10") did the trick!!

"Vergel Adriano" wrote:

something like this will give the sum of A1:A10 in Sheet1

Dim dblSum As Double
dblSum = WorksheetFunction.Sum(Sheets("Sheet1").Range("A1:A 10"))

to use a named range, you can do it this way

dblSum = WorksheetFunction.Sum(Range("NamedRange"))



--
Hope that helps.

Vergel Adriano


"I need help please" wrote:

Hello,
I have a question about creating a user defined function...

I want it to make some calculations based off of static cell ranges. I was
hoping I could use either a named range, or just type in a static range in
the function.

Like, how would I do WorksheetFunction.SUM(RANGE) in a UDF?



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

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