ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create range in udf (https://www.excelbanter.com/excel-programming/408822-create-range-udf.html)

Cresta

Create range in udf
 
Hello
Is it possible for a UDF to dimension a named range to work with inside a UDF,
I need to create a named range so I can pass it into the sumifs function
withing the UDF. I have all the other args for the sumifs but arg1 is dynamic
and this is the bit i'm stuck on.

This is what I have so far.
....
Dim SearchColumn As Range
....
SearchColumn = ???? (To be Sheets(1).Range(cells(1,x%),cells(y%,x%))
....
result = WorksheetFunction.SumIfs(SearchColumn, Column1Range,
Column1Criteria, Column2Range, Column2Criteria)
....
ICTSumIf = result


Any ideas
Thanks






joel

Create range in udf
 
udf can reference (read) anything in any workbook, but has limited write
capabilities. I like to pass ranges in to UDF's.


=myfunction(A1:B4)
or
=myfunction(columns(1:3))

function myfunction(Myrange as Range)

for each cell in Myrange
.your code
next cell

result = WorksheetFunction.SumIfs(MyRange, Column2Criteria)



end function
"Cresta" wrote:

Hello
Is it possible for a UDF to dimension a named range to work with inside a UDF,
I need to create a named range so I can pass it into the sumifs function
withing the UDF. I have all the other args for the sumifs but arg1 is dynamic
and this is the bit i'm stuck on.

This is what I have so far.
...
Dim SearchColumn As Range
...
SearchColumn = ???? (To be Sheets(1).Range(cells(1,x%),cells(y%,x%))
...
result = WorksheetFunction.SumIfs(SearchColumn, Column1Range,
Column1Criteria, Column2Range, Column2Criteria)
...
ICTSumIf = result


Any ideas
Thanks







All times are GMT +1. The time now is 05:31 PM.

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