create function with passing parameters

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i want to create my own function with passing parameters. Here's the case :

Cell A1 = 5
Cell B1 = 0

and I want cell C1 = 00005

i have this function but i don't know how to insert in macro :

Function TextInfix(CurrChar As String, CharInfix As String, TextLong As
Integer) As String
Dim CharLong As Integer, TmpInfix$

CharLong = Len(CurrChar)

TmpInfix = String(TextLong - CharLong, CharInfix) & CurrChar

TextInfix = TmpInfix
End Function
 
Is this what you want

Function TextInfix(CurrChar As String, CharInfix As String, _
TextLong As Integer) As String

TextInfix = Application.Rept(CharInfix, TextLong) & CurrChar
End Function


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
Thank you Bob Phillips

Yes, your code makes it so simple.

And now there are another problem, I create this function at PERSONAL.XLS
and I'm able to run the function in PERSONAL.XLS but i can't run it at
another workbook.

Do you know why this things happened ?
 
Thank you Niek Otten

I create the function at PERSONAL.XLS & run perfectly on PERSONAL.XLS but i
cannot run it in another workbook, do you know why ?
 
You can do it with

=Personal.xls!TextInfix(char1,char2,len)

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
Try:

=personal.xls!testinfix(a1,b1,5)

====
Another option is to save your personal.xls file as an addin (personal.xla).
Then you won't need that syntax.

But you won't see any macros in personal.xla in the tools|macro|macros dialog,
either.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top