I am using below UDF from Chip Pearson which accepts an input array as arguments (here ranges are entered as argument).
Before proceeding with the main code, this function checks if there are any arguments by using "Is Nothing".
As long as i use this udf directly on a worksheet, it works fine. For example: =COUNTA(ProperUnion(A1:A10)) works fine.
But, when i call this function from another vba code and pass my variant array as argument to this function, the "Is Nothing" check fails with Error 424: Object Required.
Note: the variant array i am passing to this function contains "Ranges" as elements.
(when I stepped into the code during debug, it stopped execution after testing with "Is Nothing". This line gave the error 424 when tested in the immediate window.)
Is this because the arguments are passed from one array v/s them being directly entered via. formula?
Can someone tell me what is the problem here?
Before proceeding with the main code, this function checks if there are any arguments by using "Is Nothing".
As long as i use this udf directly on a worksheet, it works fine. For example: =COUNTA(ProperUnion(A1:A10)) works fine.
But, when i call this function from another vba code and pass my variant array as argument to this function, the "Is Nothing" check fails with Error 424: Object Required.
Note: the variant array i am passing to this function contains "Ranges" as elements.
(when I stepped into the code during debug, it stopped execution after testing with "Is Nothing". This line gave the error 424 when tested in the immediate window.)
Is this because the arguments are passed from one array v/s them being directly entered via. formula?
Can someone tell me what is the problem here?
VBA Code:
Function ProperUnion(ParamArray MyRanges() As Variant) As Range
' Credits: Chip Pearson (cpearson.com)
If MyRanges(LBound(MyRanges)) Is Nothing Then '<-- Error 424 when calling this function from below Function
ProperUnion = Nothing
Exit Function
End If
'.
'Rest of the code
'.
End Function
'My Function calling the above code
Function RngToCellAddress(ParamArray MyRng() As Variant) As String
Dim Temp_MyRng() As Variant 'Used to Redim a ParamArray, which is Not directly allowed
'.
'. My Code
'.
Temp_MyRng = MyRng '<-- checked (array was copied correctly)
For Each mycell In ProperUnion(Temp_MyRng).Cells '<-- Calling above function
' and passing this variant
' array as input.
' some code to loop thru each cell
Next mycell
'.
'.