View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Problem adding the values of 2 TextBoxes

TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + ...

But this won't help if those textboxes contain real text.

I'd check each textbox for numeric data

Dim mySum as double

mySum = 0
if isnumeric(me.textbox13.value) then
mysum = mysum + cdbl(me.textbox13.value)
end if
if isnumeric(me.textbox23.value) then
mysum = mysum + cdbl(me.textbox13.value)
end if
....
me.textbox1.value = mysum

or...

Dim iCtr as long
dim mySum as double

mysum = 0
for ictr = 13 to 63 step 10
if isnumeric(me.controls("textbox" & ictr).value) then
mysum = mysum + me.controls("textbox" & ictr).value
end if
if isnumeric(me.controls("textbox" & ictr + 1).value) then
mysum = mysum + me.controls("textbox" & ictr + 1).value
end if
next ictr
me.textbox1.value = mysum


"Patrick C. Simonds" wrote:

Thanks Gary

But of course my problems continue. The full line of code is below, and my
problem is that if any one of those TextBoxes is blank, I get a Type
Mismatch error. I am trying to avoid using helper cells on the worksheet.

Any ideas on how I can get it to ignore blank TextBoxes?

TextBox1.Value = CDbl(TextBox13.Value) + CDbl(TextBox23.Value) +
CDbl(TextBox33.Value) + CDbl(TextBox43.Value) + CDbl(TextBox53.Value) +
CDbl(TextBox63.Value) + CDbl(TextBox14.Value) + CDbl(TextBox24.Value) +
CDbl(TextBox34.Value) + CDbl(TextBox44.Value) + CDbl(TextBox54.Value) +
CDbl(TextBox64.Value)

"Gary Keramidas" wrote in message
...
sorry, don't know what I was thinking

CDbl(Me.TextBox2.Value) + CDbl(Me.TextBox1.Value)

--


Gary K



"Patrick C. Simonds" wrote in message
...
Can anyone tell me why these do not add together?

TextBox1 = TextBox13.Value + TextBox23.Value

Lets say the value of TextBox13 is 53 and the value of TextBox23 is 10.
Instead of returning 63 I get 5310.



Below is the code that generates the value of TextBox13

TextBox13.Value = (TimeValue(TextBox12.Value) -
TimeValue(TextBox11.Value)) * 24
TextBox13.Value = Format(TextBox13.Value, "0.0000")



TextBox12 value is entered by the user as a time without the : such as
1843 for 6:43 pm and then converted to the correct format by the code
below


Private Sub TextBox12_AfterUpdate()

TextBox12.Value = Format(Application.Text(Replace(TextBox12.Value,
":", ""), "00\:00"), "hh:mm")

End Sub



--

Dave Peterson