"type mismatch" in the label caption

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to perform a calculation in vba but when the program does it the error "Type mismatch" appears because the result is 0, can someone help me?

value_1.jpg




value_2.jpg





type_mismatch.jpg
 

Attachments

  • value_1.jpg
    value_1.jpg
    115.4 KB · Views: 31

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Your variables contain text, which is what causes the error. "35" + "-15" actually evaluates to "35-15" (because both arguments are text, the + operates the same way as & would) not to 20.
 
Upvote 0
Your variables contain text, which is what causes the error. "35" + "-15" actually evaluates to "35-15" (because both arguments are text, the + operates the same way as & would) not to 20.
friend, but the error only occurs when the account value is 0, in the other forms I have the formulas exactly the same and as the result is not 0 the formula results and assumes the correct value
 
Upvote 0
Your variables contain text, which is what causes the error. "35" + "-15" actually evaluates to "35-15" (because both arguments are text, the + operates the same way as & would) not to 20.
and my variable is set to "variant"
 
Upvote 0
35-15 is not 0, so I'm not sure where you are getting that idea from.
 
Upvote 0
And your variants contain text.
but if i put the value of the variables as integer when the value is empty it as the type is "integer" it will always assume the value as "0" right? Is that in my program the variable can be empty, how can I solve the problem like that?
 
Upvote 0
In the pictures you posted, the calculation is not 0.
 
Upvote 0
If an empty textbox is not a valid input, you need to handle that in whatever manner is appropriate - eg treat it as 0, or flag it as an error to the user.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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