Not Sure why i get this typemismatch 13 error

Siyanna

Well-known Member
Joined
Nov 7, 2011
Messages
1,146
Private Sub CommandButton1_Click()
Me.TxtDays.Value = Me.TxtEndDate.Value - Me.TxtStartDate.Value
Me.TxtCons.Value = Me.TxtEndNumber.Value - Me.TxtStartNumber.Value
End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Maybe try

Code:
Private Sub CommandButton1_Click()
Me.TxtDays.Value = DateValue(Me.TxtEndDate.Value) - DateValue(Me.TxtStartDate.Value)
Me.TxtCons.Value = Val(Me.TxtEndNumber.Value) - Val(Me.TxtStartNumber.Value)
End Sub
 
Upvote 0
Maybe try

Code:
Private Sub CommandButton1_Click()
Me.TxtDays.Value = DateValue(Me.TxtEndDate.Value) - DateValue(Me.TxtStartDate.Value)
Me.TxtCons.Value = Val(Me.TxtEndNumber.Value) - Val(Me.TxtStartNumber.Value)
End Sub

Hi Vog

Am i right in saying Val converts a text string number to number i.e "5" to 5
and datevale converts text string date to number) i.e "12/04/1985" to 12/04/1985?


Thank You
 
Upvote 0
Yes, correct.

Thank U

Just another quick Q

Wht if i wanted to do the opposite and convert number to string, what function would i use instead of Val and Datevalue?

i.e

01/01/2012 to "01/01/2012" and 10 to "10"?

Thanks
 
Upvote 0
For a date

=FORMAT(mydate, "dd/mm/yyyy")

For a number

=CStr(mynumber)
 
Upvote 0

Forum statistics

Threads
1,203,538
Messages
6,055,995
Members
444,839
Latest member
laurajames

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