Search code examples
excelexcel-2010excel-udfvba

Eomonth in Excel


How can I use this function in a user-defined function? I just cannot use a reference to a cell.

Function SONxMonth()
   SONxMonth = EOMONTH(A1, 0) + 1
End Func

Solution

  • You need to use the WorksheetFunction which are used as a container for Microsoft Excel worksheet functions that can be called from Visual Basic.

    Function SONxMonth() SONxMonth = WorksheetFunction.EoMonth(Range("A1"), 0) End Func