Adding numbers

F

Fuzzhead

I have a userForm with 3 rows and 14 textboxes in each row. Each textbox is a
day. So in Row 1 I would enter the hours on site for each day. Row 2 I would
enter the hours at another job for each day and Row 3 would add Row 1 and Row
2 for each day. Then I have another textbox that would add all of Row 3 and
give me a Grand Total.

Example:
Day 1
Row 1 Row 2 Row 3
8.75 4 12.75

Day 2
Row 1 Row 2 Row 3
8 8

Grand Total: 20.75


How do I add numbers with decimals?
 
D

Doug Robbins - Word MVP

I am assuming that you are actually using what is called an in-line form (in
a document that is protected for filling in forms) rather than a UserForm
which is a custom dialog.

If that is the case, each formfield will have (or needs to have a bookmark
assigned to it and I am assuming that these bookmarks are given the names

job1day1, job1day2 ... job1day14
job2day1, job2day2 ... job2day14

In that case in row three, in the properties dialog for each of the
formfields, you would set the type of formfield to a Calculation type and
for the expression you would use

=job1day1+job2day1

for the first day and the equivalent for each of the other days and you
would set the number format to 0.00

Be aware however that you will get an error if you try and total the results
in row 3 to get the grand total. For that you will have to use

=job1day1+job2day1+job1day2+job2day2+ ... +job1day14+job2day14

You might be better off to use Excel for this.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
F

Fuzzhead

No, I was using a UserForm. Because I perform other calculations and fill in
other parts of the document with that information.
I have the following macro that works if I use numbers without decimals.
Can this be modified so I can use decimals like 8.5 or 9.75?

Sub TextBox1_Change()
Dim Nbr1 As Integer, Nbr2 As Integer, GTNbr1 As Integer
If TextBox1 = "" Then
Nbr1 = 0
Else
Nbr1 = TextBox1
End If
If TextBox15 = "" Then
Nbr2 = 0
Else
Nbr2 = TextBox15
End If
GTNbr1 = Nbr1 + Nbr2
TextBox29 = GTNbr1
TextBox92 = (GTNbr1 + GTNbr2 + GTNbr3 + GTNbr4 + GTNbr5 + GTNbr6 + _
GTNbr7 + GTNbr8 + GTNbr9 + GTNbr10 + GTNbr11 + GTNbr12 + _
GTNbr13 + GTNbr14)
End Sub
 
G

Greg Maxey

A large part of your problem is in the declaration statement.

Declaring Nbr1 as Integer forces whatever number Nbr1 may be to an integer
value (i.e., an whole number).

Sub Demo()
Dim oN1 As Integer, oN2 As Integer, oN3 As Integer
oN1 = 1.25
oN2 = 2.25
oN3 = 3.25
MsgBox oN1 + oN2 + oN3
Dim oN4 As Double, oN5 As Double, oN6 As Double
oN4 = 1.25
oN5 = 2.25
oN6 = 3.25
MsgBox oN4 + oN5 + oN6
End Sub
 
F

Fuzzhead

Thanks for the help. I knew it was something simple, but I couldn't figure it
out.
 

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

Top