Results 1 to 9 of 9

Thread: how to call excel function through VBA Macro?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    malaysia
    Posts
    89

    Resolved how to call excel function through VBA Macro?

    can anyone tell me how to call call excel sum function through macro?
    Last edited by kkc; May 31st, 2005 at 07:51 AM. Reason: i had solved it

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: how to call excel function through VBA Macro?

    If you mean you want the total (sum) of a rnage of cells, but do no want to put it in a cell - I haven't come across doing that, without making a code loop to go through all the cells and add them up if they are numeric value.

    If you have a spare cell, you could put the formula in it then grab the value.

    Which ever way you manage to do it- please post up how you did it, as I would be interested.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: how to call excel function through VBA Macro?

    you can get the sum by using exactly the same formula as you would put in a cell and assingning it to a cell or a variable


    pete

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: how to call excel function through VBA Macro?

    Pete
    Do you have an example pls? Assign to a variable I mean.

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: how to call excel function through VBA Macro?

    Set myrange = Sheet1.Range("a1:a6")
    myvar = Application.WorksheetFunction.Sum(myrange)


    tested now

    pete

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    malaysia
    Posts
    89

    Resolved Re: how to call excel function through VBA Macro?

    a more simple example is


    cells(rowindex, columnindex) = formulaExpression

    where formulaExpression is a string variable

    i.e

    // X,Y are rowindex,columnindex
    // you need to calculate x, y first then concatenate the string
    formulaExpression = "=SUM(AX:AY)"
    cells(rowindex, columnindex) = formulaExpression

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: how to call excel function through VBA Macro?

    that works, but ecniv asked to assign to variable,

    pete

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2004
    Location
    malaysia
    Posts
    89

    Re: how to call excel function through VBA Macro?

    pete, actually your solution is much more better than me in terms of development.
    any way, since i am just writing a macro for excel i think my version is enough for me.

    i think my title misleading you guys.
    this is my first time writing a macro.

  9. #9
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: how to call excel function through VBA Macro?

    Pete:
    Neat, thanks. Should've guessed there is a worksheetfunction method
    I'll remember that for the future

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width