defign a function in one workbook and use it in another workbook

D

Dean@ERYC

I am trying to open a workbook eg book2.xls from vba code in book1.xls and
want to then use a user defigned function defigned in book1.xls in book2.xls.

I can open book2.xls ok and can insert columns and paste 'normal' excel
functions into the cells but want to paste a user defigned function in and
cannot work out how to do it.

Any help greatly aprechiated.

Dean.
 
B

Bob Phillips

=mybook.xls!myfunc()

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
D

Dean@ERYC

The following code works:
Columns("W:W").Select
Selection.Insert Shift:=xlToRight
Range("W1").Select
ActiveCell.FormulaR1C1 = "ERROR SUBMISSION DATE"
Range("W2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[-1]="""",""ERROR"","""")"
Range("W2").Select
Columns("W:W").EntireColumn.AutoFit
Set SourceRange = Range("W2")
Set fillRange = Range("W2:W" & howmany)
SourceRange.AutoFill Destination:=fillRange
Columns("W:W").Select
Selection.Font.ColorIndex = 3
Range("W2").Select

But instead of the If statement I want to run:
Function dean1(rdl1 As String, rdl2 As String)
Dim rdla As String
If rdl1 = "Lab1" Or "Lab2" Or "Lab3" And rdl2 = "" Then rdla = "Error" Else
rdla = ""
dean1 = Trim(rdla)
End Function

Don't know if this helps!

Cheers, Dean.
 
D

Dean@ERYC

Thankyou Bob, that's sorted it.

Bob Phillips said:
=mybook.xls!myfunc()

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

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

Top