problem with vba application.worksheetfunction.sum

  • Thread starter Thread starter GregJG
  • Start date Start date
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
 
Hi
in this case i would simply sum the values like
txtOptIWSPrice1.Value +
txtOptIWSPrice2.Value + txtOptIWSPrice3.Value + txtOptIWSPrice4.Value
 
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
 
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
 

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

Back
Top