simplify SUMIF stmts

M

Monique

I have to code a formula in vba.. it is below:

If(SumIf(F10:AJ10, F10, F23:AJ23)*D10>0, SumIF(F10:AJ10, F10, F23:AJ23),
(SumIF(F10:AJ10, F10, F25:AJ25)/SumIF(F10:AJ10, F10, B57:AF57))*(C25/K25))

I need to simplify this because I am going to be putting the formula in VBA.
I just don't know how to handle the many SumIf statements.

Any advice would be great.

Thanks
 
B

Bob Phillips

It doesn't look as if you can simplify it if you want to maintain the IF
test, but why do you need to put it in VBA, and what difficulties are you
envisaging? Will you write the formula to a cell within VBA, or evaluate the
formula?

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
M

Monique

If I can get rid of any part of it, I would. I have to put it in VBA because
I'm making a calculation engine in the background. This way users will not be
able to change the formulas, etc etc. I am going to be writing the formula to
a range of cells in excel.. using the range("xx").resize(etc etc)... in vba.
I am just trying to figure out the most efficient way to get this formula
coded?
 
M

michdenis

Hi Monique,

If your formula is good, try this :

you just have to put your formula into brackets on the same line and you will get your result in your variable.

Dim MyVar As Double

MyVar = [If(SumIf(F10:AJ10, F10, F23:AJ23)*D10>0,SumIF(F10:AJ10, F10, F23:AJ23),(SumIF(F10:AJ10, F10, F25:AJ25)/SumIF(F10:AJ10, F10,
B57:AF57))*(C25/K25))]


Salutations!




"Monique" <[email protected]> a écrit dans le message de news: (e-mail address removed)...
I have to code a formula in vba.. it is below:

If(SumIf(F10:AJ10, F10, F23:AJ23)*D10>0, SumIF(F10:AJ10, F10, F23:AJ23),
(SumIF(F10:AJ10, F10, F25:AJ25)/SumIF(F10:AJ10, F10, B57:AF57))*(C25/K25))

I need to simplify this because I am going to be putting the formula in VBA.
I just don't know how to handle the many SumIf statements.

Any advice would be great.

Thanks
 
B

Bob Phillips

So do you just want to do

Range("A1").Formula="If(SumIf(F10:AJ10, F10, F23:AJ23)*D10>0,
SumIF(F10:AJ10, F10, F23:AJ23),(SumIF(F10:AJ10, F10,
F25:AJ25)/SumIF(F10:AJ10, F10, B57:AF57))*(C25/K25))"

Range("A1").Autofill Range("A1:A100")


--

HTH

RP
(remove nothere from the email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top