I am working on the VBA code development on Excel and wanted to ask if we can call a function from a cell.
So for the Excel, we can write functions
- in a sheet
- in the workbook
- in a module
Let assume that I write a function like this:
Public Function Area(x As Double, y As Double) As Double
Area = x * y
End Function
Whenever I put the function in a module, I can call that function in a cell using the =Area(x,y)
and the Area becomes available in Excel's function list. However, when I put the same Area function in a sheet or the workbook, =Area(x,y)
doesn't work. I have tried =Sheet1!Area(x,y)
or =Book1!Area(x,y)
, but all of them returned #NAME
. I have checked on the net and here but couldn't find a way to use a function in a sheet/workbook in a cell.
Can you please let me know if it is possible or not? And if it is, can you please provide an example of how to call the function from a cell?