Shyam
Shyam

Reputation: 2377

Excel VBA: passing arguments

I am working on some Excel functionality using VB - but I am getting stuck at some examples. Current version is Excel 2007, using a blank Workbook; I've added in a module and trying a function like the following:

Function Addtwo(a, b)
  Addtwo = a + b
End Function

However, I get the error #VALUE! in my cell, when doing Addtwo(5,5). When trying to do Addtwo(B2,B3), Excel tells me my formula is wrong.

Thanks,

Upvotes: 3

Views: 663

Answers (1)

Codo
Codo

Reputation: 78825

The pasted code is okay and works in my Excel 2007.

The only possible problems I can think of:

  • You forgot to use the equal sign: Addtwo(5,5) instead of =Addtwo(5,5)

  • Your language settings require a semicolon instead of a comma in the formula, i.e. =Addtwo(5;5) (in the worksheet formula only, not in the VBA code)

Upvotes: 5

Related Questions