none
Using math functions in Visual Basic RRS feed

  • Question

  •  

    I'm using VB to write a macro in Excel.  Now, VB has plenty of defined functions such as cos(), log(), etc., but I'd like to be able to use an _extremely_simple_ expression like

    X = sum(A, B, C)

    but I get the error that this function is not defined.  There HAS to be some way of summing besides using the "+" operator...

     

    If I use

    X = math.sum(A, B, C), I also get an error. 

     

    It would be easy to do this with spreadsheet values, but I'd like to have the calculations take place within the macro.

     

    If anyone knows how to do this, I would very much appreciate learning how!

    Thanks.

    Thursday, April 19, 2007 5:51 PM

Answers

  • You'd have more success asking this question in the Visual Basic for Applications Forum.  VBA and VB.Net are quite a bit different.

    A quick answer though:  You can use any of the Excel functions in an Excel macro.

    Thursday, April 19, 2007 6:08 PM

All replies

  • You'd have more success asking this question in the Visual Basic for Applications Forum.  VBA and VB.Net are quite a bit different.

    A quick answer though:  You can use any of the Excel functions in an Excel macro.

    Thursday, April 19, 2007 6:08 PM
  • Thanks John.  I appreciate you pointing out the distinction.  I'm sure it's apparent from my question that I'm pretty naive in this area!

     

    The Excel function example I was looking at used spreadsheet cells to contain the range, and I wanted to work with arrays soley in VB.  But now that I look closer, it appears I should be able to use Excel functions of the form Application.WorksheetFunction.<function name>()

    to do what I'm attempting. 

     

    Thanks again for responding.

    Regards,

    Frank  (a.k.a. Camcik)  

    Thursday, April 19, 2007 8:50 PM