|
-
May 31st, 2005, 12:30 AM
#1
Thread Starter
Lively Member
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
-
May 31st, 2005, 02:40 AM
#2
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.
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...
-
May 31st, 2005, 03:48 AM
#3
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
-
May 31st, 2005, 05:43 AM
#4
Re: how to call excel function through VBA Macro?
Pete
Do you have an example pls? Assign to a variable I mean.
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...
-
May 31st, 2005, 06:08 AM
#5
Re: how to call excel function through VBA Macro?
Set myrange = Sheet1.Range("a1:a6")
myvar = Application.WorksheetFunction.Sum(myrange)
tested now
pete
-
May 31st, 2005, 07:51 AM
#6
Thread Starter
Lively Member
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
-
May 31st, 2005, 08:07 AM
#7
Re: how to call excel function through VBA Macro?
that works, but ecniv asked to assign to variable,
pete
-
May 31st, 2005, 09:40 PM
#8
Thread Starter
Lively Member
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.
-
Jun 1st, 2005, 02:31 AM
#9
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|