UDF not returning value

RogueCode

New Member
Joined
Aug 5, 2014
Messages
30
I am writing a UDF that essential acts as the function LARGE but utilises a dynamic range.

When I run it, it returns Value, but I can't see what the issue is. kRange is a particular Cell on the sheet that contains a range as text e.g. N13:N75; iVal is the cell that contains the nth value that I want to look up. Is there anyone who can tell me what I have missed.
Function GetLarge(kRange As Range, iVal As Range) As Double

'kRange is calculation cell
'iVal is the number

Dim RangeK As String
Dim i As Double

RangeK = kRange.Value
i = iVal.Value

GetLarge = Application.WorksheetFunction.Large(RangeK, i)

End Function
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Try this:

GetLarge = Application.WorksheetFunction.Large(Range(RangeK), i)
 
Last edited:
Upvote 0
you dont need the RangeK at all, application.worksheetfunctio.large(krange,i)

Although I am not sure of the use of this when you can use the large function anyway
 
Upvote 0
As written, Excel sees no dependency on RangeK, so will not automatically recalculate if it changes.

I agree w/ Dryver -- why not just use a formula?
 
Upvote 0
String RangeK is given a value in this code line,
RangeK = kRange.Value

and that string then feeds into
GetLarge = Application.WorksheetFunction.Large(RangeK, i)

It would help to have more understanding of the design requirement. regards
 
Upvote 0
KRange is a range so will not give a value, when you started the udf you had already stated that krange was a range so that works in the formula.

If you said RangeK = krange, I suppose that would work
 
Upvote 0
KRange is a range so will not give a value, when you started the udf you had already stated that krange was a range so that works in the formula.

If you said RangeK = krange, I suppose that would work

Saying RangeK = krange doesn't get the right result though, because RangeK is explicitly dimmed as a string.
 
Upvote 0
Are we falling out??

Why are you passing a range into a string, the formula does not want a string, it wants a range
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top