cuddling101
New Member
- Joined
- Feb 10, 2009
- Messages
- 34
I am having problems with passing an array into a UDF.
I have essentially copied most of the code from an Excel discussion board, but I am getting the #VALUE error when the code runs. I have tried some debugging and received some information like Type mismatch with regard to trying to 'examine', via the Immediate window, the range passed, when I inserted a breakpoint just before the For loop. I also got a 'method does not support object' error when I tried to insert a Print K statement, and mark that as a breakpoint for my debugging.
The function is seeking to count the number of cells, in a range, that have a certain colour background. The range is in another open workbook.
The function's code is -
It is called with the following call -
I split the call into three lines, just for the purpose of display in this forum. The actual call all runs together, in the calling cell, of course.
The call, after evaluation, enters the 'subject function', just as I expect, as
This whole area of passing a range into a UDF is an area I have never been that comfortable with, and I am obviously getting the syntax wrong, somewhere along the way. I wondered whether I need to pass the worksheet name, column, and rows, as separate parameters, and then build the range in the UDF, but that was just one thought.
Suggested code corrections / amendments please; with my variable names if possible, please.
With thanks in anticipation.
Best regards
Philip
Bendigo, Victoria
Australia
I have essentially copied most of the code from an Excel discussion board, but I am getting the #VALUE error when the code runs. I have tried some debugging and received some information like Type mismatch with regard to trying to 'examine', via the Immediate window, the range passed, when I inserted a breakpoint just before the For loop. I also got a 'method does not support object' error when I tried to insert a Print K statement, and mark that as a breakpoint for my debugging.
The function is seeking to count the number of cells, in a range, that have a certain colour background. The range is in another open workbook.
The function's code is -
Code:
Function Families_in_Generation(Gen_Colour As Long, Families_List As Range) As Long
Dim fGen_Colour As Long
Dim fFamilies_List As Range
Dim fCell As Range
Dim K As Long
K = 0
fGen_Colour = Gen_Colour
fFamilies_List = Families_List
For Each fCell In fFamilies_List
If fCell.Interior.ColorIndex = fGen_Colour Then
K = K + 1
End If
Next fCell
Families_in_Generation = K
End Function
It is called with the following call -
Code:
=Families_in_Generation((Get_Cell_Colour((INDIRECT("'[Samuel_Johnson_and_Anne_Lawler_Descendants_Book_Control.xlsx]Samuel Johnson'!$" _
&(VLOOKUP((SHEET()), [Samuel_Johnson_and_Anne_Lawler_Descendants_Book_Control.xlsx]Gens_to_Columns!$A$2:$B$15,2,FALSE))&"$1",TRUE)))), _
(Genealogical_Service_Users_Tracing_Project_Families.xlsm!Statistics_1:Genealogical_Service_Users_Tracing_Project_Families.xlsm!Last_Family))
I split the call into three lines, just for the purpose of display in this forum. The actual call all runs together, in the calling cell, of course.
The call, after evaluation, enters the 'subject function', just as I expect, as
Code:
= Families_in_Generation(255, [Genealogical_Service_Users_Tracing_Project_Families.xlsm]Coverage_Statistics!$A$2:$A$94))
This whole area of passing a range into a UDF is an area I have never been that comfortable with, and I am obviously getting the syntax wrong, somewhere along the way. I wondered whether I need to pass the worksheet name, column, and rows, as separate parameters, and then build the range in the UDF, but that was just one thought.
Suggested code corrections / amendments please; with my variable names if possible, please.
With thanks in anticipation.
Best regards
Philip
Bendigo, Victoria
Australia
Last edited: