Having an Issue Using WorksheetFunction in a UDF

cerfani

Well-known Member
Joined
Dec 15, 2014
Messages
1,136
Hi I have what I thought was a simple task but I keep getting unexpected results... I googled around but could not find an answer so hopefully this question is not redundant...

I am creating a UDF which is going to wrap some regular excel functions. This UDF will reference ranges in one of the sheets and this UDF is saved in a module that is part of the same workbook.

I am doing this and it only returns 0... note... this is not the actual final code but I wrote this to test... and the test failed ;)



Code:
Function TestFunc()
    TestFunc = WorksheetFunction.Index(Sheet1.Range("A2:A10"), 1)
End Function

so on Sheet1, in ranges A2 through A10... there are random values... so i assumed the value in A2 would be returned but I only get 0...

I know my problem must be basic but I am more of a beginner with VBA (not a beginner to programming or excel)

Thanks to whoever is reading :)
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

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