User Defined Worksheet Functions?

B

Brad

Can I compose a function in VBA and refer to it in a
formula?

Let's say A1 has the text: "aja,ajsd," and I want to use a
formula to call the function I've created:
=ParseComma(A1)
or perhaps qualifying it more? =Module1.ParseComma(A1)
to return "ajaajsd" to the field?

If I can't, why not? Can Add-ins do it?

Thanks for the info.

-Brad

PS: I'm not interested in a solution to parse a comma, but
thanks. :)
 
B

Bob Phillips

Yes you can do exactly what you have described.

Did you try it and get a problem then ?

By the way, an add-in is just another workbook where there are no visible
worksheets, it can have functions subs and even data as any other worksheet.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
H

Harald Staff

Sure. Open VB editor (Alt F11 or similar). menu Insert > Module. Then type something like

Function RemoveStuff(FromWhat As String, _
RemoveWhat As String) As String
RemoveStuff = Replace$(FromWhat, RemoveWhat, "")
End Function

(Note all the declarations, here all As String)

Then return to a worksheet. In A1 type ABCD. In B1 type
=RemoveStuff(A1,"C")
You'll also find it under Insert > Function > category Custom or User Defined.
 
Top