how to? custom worksheet function using VBA

  • Thread starter Thread starter Fred Allen
  • Start date Start date
I don't have Excel 2007, but doesn't it work the same way? You just
put the UDF in a standard code module in the workbook where it's going
to be used. For example:

Function MySum(intNum1 As Integer, intNum2 As Integer) As Integer
MySum = intNum1 + intNum2
End Function


Then just put "=MySum(1,2)" in your worksheet cell.

??

--JP
 
I did just that, and that is what the MS article says. So at least I know I
am on the right track (with VBA UDF, which operate differently than the old
XLM UDF). I guess it is some trick in Excel 2007 (or Vista).

Thank you for confirming how I thought it was supposed to work. That does
help!


I don't have Excel 2007, but doesn't it work the same way? You just
put the UDF in a standard code module in the workbook where it's going
to be used. For example:

Function MySum(intNum1 As Integer, intNum2 As Integer) As Integer
MySum = intNum1 + intNum2
End Function


Then just put "=MySum(1,2)" in your worksheet cell.

??

--JP
 
Okay, the UDF has to be in a Module, it can't be in the code for a worksheet
or even ThisWorkbook.
 
Sorry Fred, I just realized your first post mentioned Excel 5, where
the method for creating UDFs might have been radically different. Yes
you put the code in a standard module by pressing Alt-F11 to access
the VBIDE, then going to Insert > Module in the workbook in which you
want to use the function.
 
Back
Top