adding numbers from different fields to date

ajitexcel

Board Regular
Joined
Feb 27, 2012
Messages
66
Office Version
  1. 2019
Platform
  1. MacOS
Hello
i have a form with 4 text box. TB1 to TB4. TB1 and TB2 accept numbers and TB3 is the start date TB4 is end date i.e. TB1 + TB2 + TB3.
i am not able add TB1 and TB2 it concatenating them i.e. if i enter 1 in TB1 and 1 in TB2 it should add 2 to TB3 but it is adding 11.

Private Sub TB2_Change()
Dim sResult As String
Dim TB1, TB2 As String
Dim DateFrom As Date
Dim ExtraDays As Double

TB1 = Me.TB1.Value
TB2 = Me.TB2.Value

DateFrom = Me.TB3.Value
ExtraDays = (TB1 + TB2)
If IsNull(TB1) Or TB1 = "" Then
ExtraDays = Sum("0" + TB2)
sResult = DateAdd("d", ExtraDays, DateFrom)
Else
ExtraDays = Sum(TB1 + TB2)
sResult = DateAdd("d", ExtraDays, DateFrom)
End If
Me.TB4.Value = sResult
Me.TB4 = Format(Me.TB4, "dd mmm yyyy")
End Sub
i even tried
- ExtraDays = val(TB1 + TB2)
- ExtraDays = CInt(TB1 + TB2)
none of these work it adds 11 instead of 2
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,215,986
Messages
6,128,115
Members
449,423
Latest member
Mike_AL

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