Reputation: 37
Trying to sum inputs from a userform into one cell, the inputs are numbers so i would think it would be easy, but instead of summing the inputs, the code I'm using (Below) is concatenating them like strings instead
Sub Days()
A = input1.Value + input2.Value + input3.Value + input4.Value
B = input5.Value + input6.Value = input7.Value + input8.Value
If Box1.Value = True Then
Range("A1").Value = Range("A1").Value + A
Range("A2").Value = Range("A2").Value + B
End If
If Box2.Value = True Then
Range("B1").Value = Range("B1").Value + A
Range("B2").Value = Range("B2").Value + B
End If
If Box2.Value = True Then
Range("C1").Value = Range("C1").Value + A
Range("C2").Value = Range("C2").Value + B
End If
End Sub
I have already tried Dim both A & B as integer first, not using the variables at all and just having the addition of all inputs in each if statement, all with a data type error after the first and the same concatenation issue with the second
Currently, If the inputs were 4,3,7,2,8,10,5,9 instead of adding 16 & 22 to the appropriate range, it spits out 4372 & 81059
Upvotes: 0
Views: 57
Reputation: 166615
You can do this:
A = CInt(input1.Value) + CInt(input2.Value) + CInt(input3.Value) + CInt(input4.Value)
...assuming all your values are integers - use CLng/CDbl etc if you have other types of number.
Upvotes: 1