problem with vba application.worksheetfunction.sum

G

GregJG

when I use this code on a form

Application.WorksheetFunction.Sum(txtOptIWSPrice1.Value
txtOptIWSPrice2.Value, txtOptIWSPrice3.Value, txtOptIWSPrice4.Value)

everything is fine unless one of the textboxes has no value, they ar
not all always used. then I get this error

"unable to get the sum propoerty of the worksheetfunction class"

can anyone help
 
F

Frank Kabel

Hi
in this case i would simply sum the values like
txtOptIWSPrice1.Value +
txtOptIWSPrice2.Value + txtOptIWSPrice3.Value + txtOptIWSPrice4.Value
 
G

GregJG

That was the first thing i tried, and ended up with this.

i.e.
txtOptIWSPrice1.Value is 100
txtOptIWSPrice2.Value is 150
txtOptIWSPrice3.Value is 220
txtOptIWSPrice4.Value is 60

the answer came out to equal 10015022060

it didn't add them, but placed them in sequence.

I have removed the worksheetfunction so the code looks like this.

Application.Sum(txtOptIWSPrice1.Value, txtOptIWSPrice2.Value
txtOptIWSPrice3.Value, txtOptIWSPrice4.Value)

I no longer receive the error message, but it creates a cell value o
#VALUE if all the textboxes are not typed into.

again though, if all textboxes have a number typed in, it will produc
the right result
 
G

GregJG

I have figured out a tempoary fix.
in the properties window of each textbox, I made the value 0.

I don't like seeing the 0 in each textbox that needs it, but I guess
will have to get used to it. :)

thank
 
Top