View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel[_238_] joel[_238_] is offline
external usenet poster
 
Posts: 1
Default code to sum 8 textboxes


Try these changes. I added Trim() method and added a message box to
indicate when the data is not numeric to help isolate the problem.

Private Sub cmdCalculate_Click()
If IsNumeric(Trim(Me.txtprice1.Value)) _
And TrimIsNumeric(Me.txtprice2.Value)) _
And TrimIsNumeric(Me.txtprice3.Value)) _
And Trim(IsNumeric(Me.txtprice4.Value)) _
And Trim(IsNumeric(Me.txtprice5.Value)) _
And Trim(IsNumeric(Me.txtprice6.Value)) _
And Trim(IsNumeric(Me.txtprice7.Value)) _
And Trim(IsNumeric(Me.txtprice8.Value)) Then
Me.txtSubTotal.Value = CDbl(Me.txtprice1.Value) _
+ CDbl(Trim(Me.txtprice2.Value)) _
+ CDbl(Trim(Me.txtprice3.Value)) _
+ CDbl(Trim(Me.txtprice4.Value)) _
+ CDbl(Trim(Me.txtprice5.Value)) _
+ CDbl(Trim(Me.txtprice6.Value)) _
+ CDbl(Trim(Me.txtprice6.Value)) _
+ CDbl(Trim(Me.txtprice7.Value)) _
+ CDbl(Trim(Me.txtprice8.Value))
Else
msgbox("Amounts are not Numbers")
End If
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=154415

Microsoft Office Help