adding 4 excel

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6
Hi
I have four cells in excel that I need to add into a fifth cell.

cells A1, A9, A10 and A15 (input) (=sum (A1+A9+A10+A15))
cell A23 is the total

My problem if one of the cells are blank it does not add up and gives me and error (run time error 13)

how do I go about correcting this.

the output (total) goes into a textbox on my user form.

Code:
Dim STRTOTAL As String
Dim INTNUM1  As Integer
Dim INTNUM2 As Integer
Dim intNUM3 As Integer
Dim intNUM4, INTANSWER As Integer
  
STRTOTAL = Me.txttotal.Value
INTNUM1 = txtamt1.Value
INTNUM2 = txtamt2.Value
INTNUM3 = txtamt3.Value
INTNUM4 = txtamt4.Value
 
 If STRTOTAL = "" Then
 
 INTANSWER = INTNUM1 + INTNUM2 + INTNUM3 + INTNUM4
 Me.txttotal.Text = " SUM; " & INTANSWER
   End If
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
Welcome to the board!

From your comments, it's not completely clear why you're not just creating a function in cell A23 to add the values together and then passing that to your userform.
 

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6
let me explain further....

First my apologies, the cells I am adding up are A1 + E1 + J1 + K1 = P1

this happens for every row but with different input. I would like to have it automatically added and viewed in my textbox when I click the event.

Is there a way to put cell P1 output to textbox? but I need to do this for every cell in column P. so if the user is working on a new row (new input) it would show up on his form.

I hope this makes sense...
 

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6
ok i have altered my code but i still keep getting error...

Code:
Private Sub cmdenter_click()
Dim STRTOTAL As String
Dim INTNUM1  As Integer
Dim INTNUM2 As Integer
Dim intNUM3 As Integer
Dim intNUM4, INTANSWER As Integer
  
STRTOTAL = Me.TextBox5.Value
INTNUM1 = TextBox1.Value
INTNUM2 = TextBox2.Value
intNUM3 = TextBox3.Value
intNUM4 = TextBox4.Value
 
 If intNUM4 = "" Then
 INTANSWER = INTNUM1 + INTNUM2 + intNUM3
  
 
 GoTo finish:
 
 Else
 If intNUM3 = "" And intNUM4 = "" Then
 INTANSWER = INTNUM1 + INTNUM2
  
 
 GoTo finish:
 
 Else
 If INTNUM2 = "" And intNUM3 = "" And intNUM4 = "" Then
 INTANSWER = INTNUM1
 GoTo finish:
 
 Else
If STRTOTAL = "" Then
INTANSWER = INTNUM1 + INTNUM2 + intNUM3 + intNUM4
 End If
 
finish:
 
 Me.TextBox5.Value = " SUM; " & INTANSWER
   
   End If
End If
End If
End Sub
Private Sub cmdclr_click()
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
End Sub

Private Sub cmdexit_click()
Unload Me
End Sub
 

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196

ADVERTISEMENT

I'm still not sure if I'm clear. Do you mean that when you click the button you have code that pulls the values for the row you're on
 

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6
yes

I have a user form... that has 5 textboxs (4 with input 1 with output)

I need to have all the textboxs appear in the spreadsheet.
but I also need the 4 input boxes to be added up and shown in the output textbox (textbox5)

my problem is it does not like it when there are any blanks or zeros

I have it set up already so that the input appears in the spreadsheet. and it gets totalled up by excel formula I just can't get the total to show in the ouput textbox on my form. It shows in the correct cell on the spread sheet but not on the user form.

each row will have different numbers on it to be added and shown in the output textbox. But no matter what I try with this test program listed above I still can't get it to show.

any ideas?
 
Last edited:

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6

ADVERTISEMENT

can you show me some code to hep figure this out please...
 

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
1. At what point and for what purpose do you activate the userform?
2. Are the boxes in the form populated from the spreadsheet or entered into the userform?
3. Would it help to have the userform put a formula into column P to add the values?

I might be really missing the point here, but as things currently stand, I'm afraid I'm at a loss to know how to help you. Maybe someone else might have a better understanding?

Apologies

DW
 

vbanewbie2

New Member
Joined
Jul 18, 2010
Messages
6
no now your on the right track with me....

the userform is the main input to the spreadsheet, the user will see the form and add all input through it.

the boxes are populated by the user through the userform

I'm not sure how to do that add the values to comlumn p for each time the user adds another row / client / person what ever the case may be.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,310
Messages
5,641,450
Members
417,210
Latest member
rins

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
Top