ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   defign a function in one workbook and use it in another workbook (https://www.excelbanter.com/excel-programming/375306-defign-function-one-workbook-use-another-workbook.html)

Dean@ERYC[_2_]

defign a function in one workbook and use it in another workbook
 
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.

Bob Phillips

defign a function in one workbook and use it in another workbook
 
=mybook.xls!myfunc()

--
HTH

Bob Phillips

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

"Dean@ERYC" wrote in message
...
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.




Dean@ERYC[_2_]

defign a function in one workbook and use it in another workbook
 
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.
"Dean@ERYC" wrote:

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.


Dean@ERYC[_2_]

defign a function in one workbook and use it in another workbo
 
Thankyou Bob, that's sorted it.

"Bob Phillips" wrote:

=mybook.xls!myfunc()

--
HTH

Bob Phillips

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

"Dean@ERYC" wrote in message
...
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.






All times are GMT +1. The time now is 03:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com