vba userform in word template - runtime error 11

lizziegirl

New Member
Joined
Apr 3, 2006
Messages
31
Hi there - I am having a little trouble with my userform in a Word Template at present.

Within my userform I have a stack of textboxes that the user enters monetary values into. They are formatted as currency on the press of a command button. This command button also calculates some addition of and division of various textboxes.

Upon pressing another command button these values go to bookmarks in the word doc.

My problem is that at the first press of this button all the calculations and code run perfectly. However if the user was to notice an error in one on their inputs, and they amend it..upon repressing the calculate command button, 9 times out of 10, the runtime error 11 occurs. I note that most of the sums have turned to zero and therefore this error occurs because the code is trying to divide by zero.

I don't understand if the code runs through again, the sums turn to zero.

If it helps, below is the code I have upon the pressing of the command button. I know there is a stack of code and I probably have seriously gone around writing it in the wrong way but I am new and am teaching myself so sorry if it is hard to comprehend!!! :oops:

Thanks in advance.
Lizzie


Code:
Private Sub cmdCalculate_Click()

'upon clicking the calculate button the below code makes the caluclations
TextBox18.Value = Val(TextBox15.Value) + Val(TextBox16.Value) + Val(TextBox17.Value)
TextBox19.Value = Val(TextBox20.Value) + Val(TextBox21.Value) + Val(TextBox22.Value)
TextBox23.Value = Val(TextBox24.Value) + Val(TextBox25.Value) + Val(TextBox26.Value)
TextBox27.Value = Val(TextBox28.Value) + Val(TextBox29.Value) + Val(TextBox30.Value)
TextBox31.Value = Val(TextBox32.Value) + Val(TextBox33.Value) + Val(TextBox34.Value)
TextBox35.Value = Val(TextBox36.Value) + Val(TextBox37.Value) + Val(TextBox38.Value)
TextBox57.Value = Val(TextBox18.Value) + Val(TextBox19.Value) + Val(TextBox23.Value) + Val(TextBox27.Value) + Val(TextBox31.Value) + Val(TextBox35.Value)
TextBox43.Value = Val(TextBox40.Value) + Val(TextBox41.Value) + Val(TextBox42.Value)
TextBox44.Value = Val(TextBox45.Value) + Val(TextBox46.Value) + Val(TextBox47.Value)
TextBox52.Value = Val(TextBox53.Value) + Val(TextBox54.Value) + Val(TextBox55.Value)
TextBox56.Value = Val(TextBox43.Value) + Val(TextBox44.Value) + Val(TextBox52.Value)
TextBox39.Value = Val(TextBox56.Value) / Val(TextBox57.Value)

'the below code then formats all the textboxes to currency
TextBox15 = Format(TextBox15, "$###,###,###.00")
TextBox16 = Format(TextBox16, "$###,###,###.00")
TextBox17 = Format(TextBox17, "$###,###,###.00")
TextBox18 = Format(TextBox18, "$###,###,###.00")
TextBox19 = Format(TextBox19, "$###,###,###.00")
TextBox20 = Format(TextBox20, "$###,###,###.00")
TextBox21 = Format(TextBox21, "$###,###,###.00")
TextBox22 = Format(TextBox22, "$###,###,###.00")
TextBox23 = Format(TextBox23, "$###,###,###.00")
TextBox24 = Format(TextBox24, "$###,###,###.00")
TextBox25 = Format(TextBox25, "$###,###,###.00")
TextBox26 = Format(TextBox26, "$###,###,###.00")
TextBox27 = Format(TextBox27, "$###,###,###.00")
TextBox28 = Format(TextBox28, "$###,###,###.00")
TextBox29 = Format(TextBox29, "$###,###,###.00")
TextBox30 = Format(TextBox30, "$###,###,###.00")
TextBox31 = Format(TextBox31, "$###,###,###.00")
TextBox32 = Format(TextBox32, "$###,###,###.00")
TextBox33 = Format(TextBox33, "$###,###,###.00")
TextBox34 = Format(TextBox34, "$###,###,###.00")
TextBox35 = Format(TextBox35, "$###,###,###.00")
TextBox36 = Format(TextBox36, "$###,###,###.00")
TextBox37 = Format(TextBox37, "$###,###,###.00")
TextBox38 = Format(TextBox38, "$###,###,###.00")
TextBox39 = Format(TextBox39, "$###,###,###.00")
TextBox40 = Format(TextBox40, "$###,###,###.00")
TextBox41 = Format(TextBox41, "$###,###,###.00")
TextBox42 = Format(TextBox42, "$###,###,###.00")
TextBox43 = Format(TextBox43, "$###,###,###.00")
TextBox44 = Format(TextBox44, "$###,###,###.00")
TextBox45 = Format(TextBox45, "$###,###,###.00")
TextBox46 = Format(TextBox46, "$###,###,###.00")
TextBox47 = Format(TextBox47, "$###,###,###.00")
TextBox52 = Format(TextBox52, "$###,###,###.00")
TextBox53 = Format(TextBox53, "$###,###,###.00")
TextBox54 = Format(TextBox54, "$###,###,###.00")
TextBox55 = Format(TextBox55, "$###,###,###.00")
TextBox56 = Format(TextBox56, "$###,###,###.00")
TextBox57 = Format(TextBox57, "$###,###,###.00")

If TextBox52.Value = "$.00" Then
TextBox52.Value = "$0.00"
End If

If TextBox18.Value = "$.00" Then
TextBox18.Value = "$0.00"
End If

If TextBox19.Value = "$.00" Then
TextBox19.Value = "$0.00"
End If

If TextBox23.Value = "$.00" Then
TextBox23.Value = "$0.00"
End If

If TextBox27.Value = "$.00" Then
TextBox27.Value = "$0.00"
End If

If TextBox31.Value = "$.00" Then
TextBox31.Value = "$0.00"
End If

If TextBox35.Value = "$.00" Then
TextBox35.Value = "$0.00"
End If

If TextBox57.Value = "$.00" Then
TextBox57.Value = "$0.00"
End If

If TextBox43.Value = "$.00" Then
TextBox43.Value = "$0.00"
End If

If TextBox44.Value = "$.00" Then
TextBox44.Value = "$0.00"
End If

If TextBox56.Value = "$.00" Then
TextBox56.Value = "$0.00"
End If

If TextBox39.Value = "$.00" Then
TextBox39.Value = "$0.00"
End If

End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,225,268
Messages
6,183,956
Members
453,198
Latest member
VB6 Programming

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top