why cant use Text() function in user defined function?

dleizer

New Member
Joined
Aug 7, 2011
Messages
11
folks

Can somebody explain to me why i am getting the following error when i try to construct a simple user defined function

The error is Compile Error: Sub or Function not defined

The user defined function I created is

Function test(dd)
test = Text(dd, "mm/dd/yy")
End Function

The "TEXT" word is highlighted when the compile error is displayed

Any ideas

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Vog's solution with Format instead of Text is definately preferred...
Because Format is a built in VBA function.

But the reason yours didn't work is because TEXT is a worksheet function, not a VBA function.
You have to tell the code that you want to use a worksheet function...

test = WorksheetFunction.Text(dd, "mm/dd/yy")
 
Upvote 0

Jonmo1 & VoG
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
Thanks for your prompt and useful response (as you expected both solutions worked!)<o:p></o:p>
As youcan see i am obviusly relatively inexperienced so off to google to learn all about worksheetFunctions (is there a list of worksheet functions?)<o:p></o:p>
<o:p></o:p>
Having tested it i now discovered that i cant use the =CONCATENATE("a","b") function in vba (get same error message) but i can’t solve the problem by using the worksheetFunction prefix <o:p></o:p>

Is there an similar explanation / solution for this and howe can one find out which functions can be used in VBA?

Thanks
 
Upvote 0
Try using

MyVariable = "a" & "b"


The & symbol does the same thing as concatenate.
Also in worksheet formulas as well.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,729
Members
452,939
Latest member
WCrawford

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