calling VBA functions from a cell

  • Thread starter Thread starter rturner138
  • Start date Start date
R

rturner138

Hi, I've got a function called add(a as int, b as int) that returns a +
b, defined in the correct sheet and workbook I'm currently using. I'd
like to be able to call this function from a cell, ie enter in cell A1
the text "=add(4,5)" (without the quote marks) and have it return the
answer. I get a NAME? error when I do this. What am I doing wrong?
 
Place this code on a normal module sheet.
It can then by used as a normal maths formula

Code will need to be modified if a or b is a multiple ranges


Function MyFunction(a As Range, b As Range) As Integer
MyFunction = a.Value + b.Value
End Function
 
Put the code in a normal code module, not the ThisWorkbook module
or one of the Sheet modules.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Back
Top