Run-time error:13 Type mismatch

Latexy

New Member
Joined
Oct 8, 2019
Messages
19
Hi.

I have this code in sub and its getting this run-time error for some reason. While debug it shows the value for change as "0" and value for textbox could be like "23.60"
If i change the variable as string it works but then calculations wont work.
VBA Code:
    Dim change As Double
    change = TextBoxChange.Value
 
Here is the code for automatic calculation for middle textbox where the problem is
VBA Code:
Sub kassa()
    Dim crechange As Double
    Dim katchange As Double
    Dim xchange As Double
   
    crechange = CDbl(TextBoxCredit.Value)
    katchange = CDbl(TextBoxKateinen.Value)
    xchange = crechange + katchange
    TextBoxKassa.Value = xchange
    TextBoxKassa = Format(TextBoxKassa.Value, "#,##0.00")
End Sub
here is the code for make it automatic
Code:
Private Sub TextBoxCredit_Change()
    If Not TextBoxCredit.Value = "" And Not TextBoxKateinen.Value = "" Then
        Call kassa
    Else
        TextBoxKassa.Value = ""
    End If
End Sub

Private Sub TextBoxKateinen_Change()
    If Not TextBoxCredit.Value = "" And Not TextBoxKateinen.Value = "" Then
        Call kassa
    Else
        TextBoxKassa.Value = ""
    End If
End Sub
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
You'll get an error if the textbox you are referring to is empty, so you should either check for that first or use

Code:
CDbl("0" & textboxname.text)
 
Upvote 0
What is the error message, on which line of code does it occur, and what is in the two textboxes at the time?

Note: using a Change event is not usually a good idea since it fires for every key stroke.
 
Upvote 0
Well i changed the code that it's not using the Change event anymore and now the problem is that if the number in textbos is given 5,5 the code changes it to 43590,00.
I think it's because the comma but can't figure it out...
 
Upvote 0
43590 is the numeric representation of 5th May 2019, so I think your system seems to be setup to use a comma as the date separator?
 
Upvote 0
Hi!
I tried to change the separator to dot and after that got Run-time error:13 Type mismatch when code tried to give the value to Double type variable. I really don't get this :unsure:
 
Upvote 0
You need your system to use a date separator that isn’t the same as your decimal or list separators.
 
Upvote 0
Thanks. I changed the numeral separator in windows settings from comma to dot and now it works :)
There's still the problem if the file is used on several computers that all must be made the same changes :unsure:
 
Upvote 0

Forum statistics

Threads
1,214,823
Messages
6,121,779
Members
449,049
Latest member
greyangel23

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