Error 13 - Type Mismatch

tigerdel

Board Regular
Joined
Oct 13, 2015
Messages
145
Office Version
  1. 365
Platform
  1. Windows
In my UserForm I have a number TextBoxes and ComboBoxes and I am trying to get 2 TextBoxes to sum values

1601460411391.png


A – [txtQty] Quantity entered by user
B – [cmbMarkUp] Mark Up chosen by User
C – [txtPrice] Unit Price added by code
D – [txtMarkUp] Code below
E – [txtTotal] Code below

For D & E, I added the following code but get the Error 13 - Type mismatch error

Code:
Private Sub cmbMarkUp_Change()
txtMarkUp.Value = txtPrice.Value * (1 + cmbMarkUp.Value)
txtTotal.Value = txtPrice.Value * txtQty
End Sub

Any ideas??

Many thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,
what you have in your textbox & combobox is Text - try using a type conversion function to coerce your text to the required data type & see if this resolves your issue

Rich (BB code):
Private Sub cmbMarkUp_Change()
    txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value))
    txtTotal.Value = Val(txtPrice.Value) * Val(txtQty)
End Sub

The Val function stops reading the string at the first character that it is not able to recognize as part of a number or if no valid numeric value, it returns Zero.

Dave
 
Upvote 0
Hi
Try some thing like this
VBA Code:
TextBox3 = TextBox1 * 1 + TextBox2 * 1
 
Upvote 0
Hi,
what you have in your textbox & combobox is Text - try using a type conversion function to coerce your text to the required data type & see if this resolves your issue

Rich (BB code):
Private Sub cmbMarkUp_Change()
    txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value))
    txtTotal.Value = Val(txtPrice.Value) * Val(txtQty)
End Sub

The Val function stops reading the string at the first character that it is not able to recognize as part of a number or if no valid numeric value, it returns Zero.

Dave

Thanks Dave
That did kind of work except for some reason it txtMarkUp.Value has the decimal place one to the right

i.e. I added one item at 28.8 and added 10% from cmbMarkup and instead of 31,68 in txtMarkUp it shows 316.8

Any ideas??
 
Upvote 0
I added one item at 28.8 and added 10% from cmbMarkup and instead of 31,68 in txtMarkUp it shows 316.8

Any ideas??

try dividing cmbMarkup by 100 and see if that resolves

Rich (BB code):
txtMarkUp.Value = Val(txtPrice.Value) * (1 + Val(cmbMarkUp.Value) / 100)

Dave
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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